Can anyone fix my code using If and ElseIF?

kbj0109

New Member
Joined
Mar 28, 2015
Messages
26
I have three blank text boxes in a UserForm.

All of them should not be blank, or It gets message 'Fill All of Them'
and also, if the value in the third text box is not a Date format, I want a message box "Enter A Date"


Somehow,, my code is not working..
Please somebody help me out..
ElseIf should be used to check the data format of Date. and I don't know how...

This is my current code

If Text1.Value = "" Then
If Text2.Value = "" Then
If Date3.Value = "" Then
MsgBox "Fill All of Them"

ElseIf IsDate(Date3.Value) Then
MsgBox "Enter A Date"

End If
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Each 'If' needs a 'End If'.
Or you write something like this:
If....then
....
else
....If .....then
....else....
....end if
End if

or you can write like this:

if

elseif

elseif

elseif

end if
 
Upvote 0
For your code, you can use the 'Or' operator.

Code:
If Date3.Value = "" Then
     If Text1.Value = "" Or Text2.Value = "" Then
              MsgBox "Fill All of Them"
     Else
             MsgBox "Enter A Date"
     End If
End If
 
Upvote 0
Try This:
Code:
Private Sub CommandButton2_Click()
If TextBox1.Value = "" Or TextBox2.Value = "" Then MsgBox "Fill All Of Them"
If IsDate(Date3.Value) = False Then MsgBox "Enter A Date"

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top