Vba if statement question

Last Edited By Krjb Donovan
Last Updated: Mar 05, 2014 10:02 PM GMT

Question

good evening..i would like to ask how to combine all different if statement in only one message box...for an example:

Private Sub CommandButton1_Click() Set a = Sheets("License").Cells(9, 10) Set b = Sheets("License").Cells(10, 10) Set c = Sheets("License").Cells(11, 10)

If a = "Overdue" Then MsgBox ("Update " & Cells(9, 2) & " driving licence before " & Cells(9, 8)) End If

If c = "Overdue" Then MsgBox ("Update " & Cells(11, 2) & " driving licence before " & Cells(11, 8)) End If

If b = "Overdue" Then MsgBox ("Update " & Cells(10, 2) & " driving licence before " & Cells(10, 8)) End If End sub


cells (9,2) ,(10,2),(11,2) is person name and cells (9,8),(10,8),(11,8) are expired date...i would like to combine all these 3 message box into only 1 message box. help me plz...

Answer

dim strMsg as String strMsg = "" If a = "Overdue" Then

    strMsg = strMsg & vbcrlf & vbcrlf & "Update " & Cells(9, 2) & "  driving licence before " & Cells(9, 8)

End If

If c = "Overdue" Then

    strMsg = strMsg & vbcrlf & vbcrlf & "Update " & Cells(11, 2) & " driving licence before " & Cells(11, 8)

End If

If b = "Overdue" Then

    strMsg = strMsg & vbcrlf & vbcrlf & "Update " & Cells(10, 2) & " driving licence before " & Cells(10, 8)

End If

if strMsg <> "" then

    MsgBox strMsg

endif End sub


Advertisement

©2021 eLuminary LLC. All rights reserved.