Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
If statement question
I have a macro that pops up a message box asking the user for an
number input. I want to have the macro run for all inputs greater than 1. If the user puts in "1", I want to have the macro just ignore it and do nothing. Is that possible with an if statement? Is that the best way? If the user doesn't input "1", I want the macro to do the normal operations it was coded to do. Any thoughts? Some code as an example would help greatly since I'm new with VBA. Thanks! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
If statement question
Hi,
You could do this Sub surface() Response = InputBox("Input a number 1", "Input") If Response = 1 Then Exit Sub 'do things End Sub Mike "Eric S" wrote: I have a macro that pops up a message box asking the user for an number input. I want to have the macro run for all inputs greater than 1. If the user puts in "1", I want to have the macro just ignore it and do nothing. Is that possible with an if statement? Is that the best way? If the user doesn't input "1", I want the macro to do the normal operations it was coded to do. Any thoughts? Some code as an example would help greatly since I'm new with VBA. Thanks! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
If statement question
On 16 jan, 16:37, Eric S wrote:
I have a macro that pops up a message box asking the user for an number input. *I want to have the macro run for all inputs greater than 1. *If the user puts in "1", I want to have the macro just ignore it and do nothing. *Is that possible with an if statement? *Is that the best way? If the user doesn't input "1", I want the macro to do the normal operations it was coded to do. Any thoughts? *Some code as an example would help greatly since I'm new with VBA. Thanks! Hi Eric, In Excel2003 I have created the code below. Since an InputBox returns a string some typecasting might be necessary. When the user click Cancel an empty string is returned. Sub EricS() Dim strReply As String Dim strMessage As String Do strReply = InputBox(strMessage, "Enter a number") If IsNumeric(strReply) Then If Val(strReply) = 1 Then Exit Do Else ' DO YOUR THING End If Else If Len(strReply) = 0 Then Exit Do Else strMessage = "That was not a number, try again" End If End If Loop End Sub HTH, Wouter |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
If statement question
Hi Mike -
Thanks for your help - worked perfectly! Probably seemed like an overly simple issue to you, but I learned something new, so THANKS. Eric |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
If Statement Question | Excel Worksheet Functions | |||
IF statement Question | Excel Programming | |||
If then statement question.... | New Users to Excel | |||
IF statement question | Excel Worksheet Functions | |||
Question about dim statement | Excel Programming |