Exit ? End? To end a loop

Guanjin Peter

Active Member
Joined
May 21, 2008
Messages
429
As you can see the code below, it detects cell B2 if there's a valid date or not. then pops up the msgbox
The problem here is after adding ComboBox1 = ""
the code detects the changes in ComboBox1_Change sub and pops up the msgbox again. I tried to use exit sub and end if, but doesn't stop the msgbox popping up twice. Any way to go around it?

Code:
Private Sub ComboBox1_Change()
    On Error Resume Next
    If IsDate(Range("B2")) = False Then
    MsgBox "Please Enter Delivery Date", vbExclamation, "Invalid Date" 'no update until date,cell(b1) is filled
    ComboBox1.Value = ""
    Else
'Nothing
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
What error are you expecting to get gave you a reason to need the error bypass line; nothing there will cause a run time error.

Are these controls on a userform or embedded on a worksheet.

No matter actually, if it were me, since the problem stems from a potential non-date being entered in cell B2, then just isolate that action before the userform is called, either with data validation or VBA, and if a valid date is not in B2, deny the userform from being called or keep the combobox locked until a valid date was entered first into B2. You can check for that after loading the userform on Initilization and prompt for a valid date entry before allowing access to the combobox. Lots of options at your disposal.
 
Upvote 0
just as an FYI - NOT as a "you should do this" ...

to leave a For Loop etc... Exit For
to leave a routine in full... Exit Sub
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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