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)
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