View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
RadarEye RadarEye is offline
external usenet poster
 
Posts: 78
Default 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