When you use something like If Len(I8) = 0 Then
in VBA, it will assume I8
is a variable. Since you obviously don't have that variable defined, Len(I8)
will always be zero.
What you should do is use Range("I8")
or even ActiveSheet.Range("I8").Value
instead to get the value that is actually in that cell.
So your code should change to:
If Len(Range("I8")) = 0 Then
MsgBox "Please enter Required Date", vbExclamation
Exit Sub
ElseIf Len(Range("D11")) = 0 Then
MsgBox "Please enter your name", vbExclamation
Exit Sub
ElseIf Len(Range("H11")) = 0 Then
MsgBox "Please enter Work Phone", vbExclamation
Exit Sub
ElseIf Len(Range("L11")) = 0 Then
MsgBox "Please enter Home Phone", vbExclamation
Exit Sub
End If
MsgBox "All mandatory fields have been entered", vbExclamation
End Sub
To avoid these kinds of confusing issues, you can specify Option Explicit
at the very top of the module. This causes excel to throw an error when you use undeclared variables like that instead of just silently guessing what it should do with it.