ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   if - loop? (https://www.excelbanter.com/excel-programming/335715-if-loop.html)

stefan via OfficeKB.com

if - loop?
 

Hi,
If the user input the wrong info, a msg will pop up. How can i prevent the
macro from running through the rest, but instead loop back until the user
inputs the correct info?
Thanks,
Stefan

....
....
If [ccard2].Formula Like "#" Then ' 1
MsgBox "Please enter 5 digits." & Chr(10) _
& "I.e. '04' for month, '/' for the divider and '05' for the year." &
Chr(10) _
& "This would look like 04/05." _
& Chr(10) & Chr(10) & "Thank you.", vbInformation, "Incorrect Entry
Notice"
Range("ccard2").Select
End If
MsgBox "Thank you."
....
....


--
Message posted via http://www.officekb.com

Henry[_5_]

if - loop?
 
Stefan,

Dim Flag
Flag = 0
Do Until Flag = 1
Flag = 1
If [ccard2].Formula Like "#" Then ' 1
MsgBox "Please enter 5 digits." & Chr(10) _
& "I.e. '04' for month, '/' for the divider and '05' for the
year." &
Chr(10) _
& "This would look like 04/05." _
& Chr(10) & Chr(10) & "Thank you.", vbInformation, "Incorrect
Entry
Notice"
Range("ccard2").Select
Flag = 0
End If
Loop
MsgBox "Thank you."



"stefan via OfficeKB.com" wrote in message
...

Hi,
If the user input the wrong info, a msg will pop up. How can i prevent the
macro from running through the rest, but instead loop back until the user
inputs the correct info?
Thanks,
Stefan

...
...
If [ccard2].Formula Like "#" Then ' 1
MsgBox "Please enter 5 digits." & Chr(10) _
& "I.e. '04' for month, '/' for the divider and '05' for the year."
&
Chr(10) _
& "This would look like 04/05." _
& Chr(10) & Chr(10) & "Thank you.", vbInformation, "Incorrect Entry
Notice"
Range("ccard2").Select
End If
MsgBox "Thank you."
...
...


--
Message posted via http://www.officekb.com





All times are GMT +1. The time now is 05:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com