(Solved) – VBA – Msg box when cell A not empty cell b mandatory to be filled in – currently msg box always displays

(solved)-–-vba-–-msg-box-when-cell-a-not-empty-cell-b-mandatory-to-be-filled-in-–-currently-msg-box-always-displays

I’m pretty new to VBA and have an xls template where I’m trying to build in message box for users to fill in a cell in column B as mandatory if cell in column A is not blank before the template will allow saving. Currently it pops up the message whether the cell is blank or not and once you click ok, it saves anyway. Any advise on modifying the code below for the desired action?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Sub Check()
Dim rng As Range
Dim i As Long

'Set the range in column A you want to loop through
Set rng = Range("A1:A10000")
For Each cell In rng
    'test if cell is empty
    If cell.Value <> "" Then

MsgBox “Cell in column B requires user input in the format of PH_PSIxxxxxx”

Cancel = True

End If
Next
End Sub

thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *