DesTro
DesTro

Reputation: 9

Make "If" return a comment

I'm wondering if there is a way to show up a comment if two cells have different values eg "=if(A1=B1, "show a comment", "show a comment"), Thanks

Upvotes: 0

Views: 479

Answers (2)

Sola Oshinowo
Sola Oshinowo

Reputation: 609

   Try the function below
  =IF(A1>B1,"comment",IF(A1<B1,"comment"))

Upvotes: -1

simple-solution
simple-solution

Reputation: 1139

Public Function if_then_comment(criteria, ifTrueString As String, _
    ifTrueComment As String, ifFalseString As String, ifFalseComment As String)
    
    Dim calcDefault
    Application.Volatile
    calcDefault = Application.Calculation
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False ' => disable events
    On Error Resume Next
    
    With Application.ThisCell
        If criteria Then
            if_then_comment = ifTrueString
            .ClearComments
            .AddComment (ifTrueComment)
        Else
            if_then_comment = ifFalseString
            .ClearComments
            .AddComment (ifFalseComment)
        End If
    End With
    
    On Error GoTo 0
    Application.Calculation = calcDefault
    Application.EnableEvents = True ' => enable events
End Function

enter image description here

Upvotes: 2

Related Questions