Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Statement Question Joe Excel Worksheet Functions 4 April 17th 09 06:19 PM
IF statement Question Novice Lee Excel Programming 5 August 8th 08 02:48 PM
If then statement question.... atlcasework New Users to Excel 7 January 14th 08 06:37 PM
IF statement question [email protected] Excel Worksheet Functions 2 July 24th 06 04:20 PM
Question about dim statement Gregg[_4_] Excel Programming 4 July 19th 05 03:07 PM


All times are GMT +1. The time now is 07:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"