Excel VBA help [Solved/Closed]

Report
-
 Maja WL -
Hello,
I am needing some help with this vba code. What I am trying to do is first verify if cell A4 is not empty, if it is not empty then I need it to make sure there is data in the other columns before anyone can save. This is what I got so far but it is saving and not bring the popup message that data is missing.


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

If IsEmpty(A4) = False Then 'make sure that A4 is not empty prior to running the below if


If Worksheets("User's Sheet").Range("B4").Value = "" Then
msg = "Program Short Name must be filled in before saving."
Cancel = True
End If

'and

If Worksheets("User's Sheet").Range("F4").Value = "" Then
msg = "Gender must be filled in before saving."
Cancel = True
End If

'and

If Worksheets("User's Sheet").Range("G4").Value = "" Then
msg = "Color Name must be filled in before saving."
Cancel = True
End If

'and


If Worksheets("User's Sheet").Range("H4").Value = "" Then
msg = "Size must be filled in before saving."
Cancel = True
End If

'and

If Cancel Then
MsgBox msg
End If




End If
End Sub

2 replies

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
760
I see one logical error

If IsEmpty(a4) = False Then 'make sure that A4 is not empty prior to running the below if

I think you meant

If IsEmpty(Range("a4")) = False Then 'make sure that A4 is not empty prior to running the below if
If range("A4").Value = "" Then ...