Hi all,
I am trying to code a macro that first checks cells B4,C4,D4 and E4 to check they have been filled in. If they haven't a msgbox should pop up prompting to fill in required cells. If the cells are filled in the various functions in the recorded macro should run.
Note, All relevant columns have data validation applied.
I have tried several methods. IsNull() with OR for the various cells, B4=""..., B4=0.. etc. but I can't seem to get it to work correctly.
In the code below, if the cells are empty the msgbox comes up however even when the cells are completed the msgbox comes up and the macro does not run the Else portion of the code.
If B4 = "" Then
MsgBox ("Please enter data in all cells")
ElseIf C4 = "" Then
MsgBox ("Please enter data in all cells")
ElseIf D4 = "" Then
MsgBox ("Please enter data in all cells")
ElseIf E4 = "" Then
MsgBox ("Please enter data in all cells")
Else
ActiveSheet.Unprotect
Rows("4:4").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B5:E5").Select
Range("E5").Activate
ActiveSheet.Shapes.Range(Array("Rectangle 7")).Select
Range("B5:E5").Select
Range("E5").Activate
Selection.Locked = True
Selection.FormulaHidden = False
Range("B2:E4").Select
Range("E4").Activate
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
End If
End Sub
Bookmarks