Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
IsEmpty(Range("A4"))
-- Gary''s Student - gsnu201001 |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
A slightly different approach
Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean) Dim msg(6) Dim c As Range dim x as long Set sht = Sheets("User's Sheet") msg(1) = "Cannor save A4 must be filled in" msg(2) = "Program Short Name must be filled in before saving." msg(3) = "Gender must be filled in before saving." msg(4) = "Color Name must be filled in before saving." msg(5) = "Size must be filled in before saving." x = 1 For Each c In sht.Range("A4,b4,f4,G4,H4") If IsEmpty(c) Then MsgBox msg(x) & " " & c.Address Cancel = True Exit Sub End If x = x + 1 Next End Sub -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "vmc" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|