Home > Back-end >  Make "If" return a comment
Make "If" return a comment

Time:03-01

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

CodePudding user response:

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

CodePudding user response:

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