Excel VBA help

Solved/Closed
vmc - Feb 22, 2010 at 10:43 AM
 Maja WL - Sep 25, 2010 at 05:06 PM
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
Related:

2 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Feb 22, 2010 at 10:57 AM
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
0
If range("A4").Value = "" Then ...
0