Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA IF statements

I was wondering if you can do an if statement that says "if input isn't
... then ...". Below is the code im trying to sort out, and i think
you'll understand once you see it!

ActiveCell.Offset(0, 1).Range("A1").Select
ans = Application.InputBox("Enter the customer title: ", _
"Customer Title", Type:=2) ' Type 2 for a text entry
If ans = "Miss" Or ans = "Mr" Or ans = "Ms" Or ans = "Mrs"
Then
MsgBox "Please input an appropriate title", vbOKOnly +
vbCritical, "Incorrect Input"
Application.Run "InputMe"
Exit Sub
End If
ActiveCell.Offset.Range("A1") = ans


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default VBA IF statements

Hi

I believe you want something like
If ans < "Miss" And ans < "Mr" And ans < "Ms" And ans < "Mrs" then

But my male intuition tells me that you are entering tons of personal info
this way. You should really use a userform instead of a series of inputboxes
for that. See
http://www.microsoft.com/ExcelDev/Articles/sxs11pt1.htm
for a start. (And apologies if I'm wrong ;-)

HTH. Best wishes Harald



"Joanne Toone" skrev i melding
...
I was wondering if you can do an if statement that says "if input isn't
.. then ...". Below is the code im trying to sort out, and i think
you'll understand once you see it!

ActiveCell.Offset(0, 1).Range("A1").Select
ans = Application.InputBox("Enter the customer title: ", _
"Customer Title", Type:=2) ' Type 2 for a text entry
If ans = "Miss" Or ans = "Mr" Or ans = "Ms" Or ans = "Mrs"
Then
MsgBox "Please input an appropriate title", vbOKOnly +
vbCritical, "Incorrect Input"
Application.Run "InputMe"
Exit Sub
End If
ActiveCell.Offset.Range("A1") = ans


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default VBA IF statements

Joanne: My 1 1/2 cents -
(1) Read the VBA Help on If-Then-Else statements, especially ElseIf, and see
if that's what you want. You might type ElseIf into the Answer Wizard and
see if the topics there help at all.
(2) What are you using Offset with Range("A1").Select? Offset moves the
selection (or active cell) from where it is to another cell relative to the
active cell - (0,1) would move it to the right one cell in the same row.
Range("A1").Select will take you from wherever you are directly to A1. You
likewise don't need it to assign ans to A1 - Range("A1") = ans will do.
(You do have Dim ans As String in the beginning of this, right?)

Ed

"Joanne Toone" wrote in message
...
I was wondering if you can do an if statement that says "if input isn't
.. then ...". Below is the code im trying to sort out, and i think
you'll understand once you see it!

ActiveCell.Offset(0, 1).Range("A1").Select
ans = Application.InputBox("Enter the customer title: ", _
"Customer Title", Type:=2) ' Type 2 for a text entry
If ans = "Miss" Or ans = "Mr" Or ans = "Ms" Or ans = "Mrs"
Then
MsgBox "Please input an appropriate title", vbOKOnly +
vbCritical, "Incorrect Input"
Application.Run "InputMe"
Exit Sub
End If
ActiveCell.Offset.Range("A1") = ans


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default VBA IF statements

Have you considered using Cell Validation on the input cell?

"Joanne Toone" wrote:

I was wondering if you can do an if statement that says "if input isn't
... then ...". Below is the code im trying to sort out, and i think
you'll understand once you see it!

ActiveCell.Offset(0, 1).Range("A1").Select
ans = Application.InputBox("Enter the customer title: ", _
"Customer Title", Type:=2) ' Type 2 for a text entry
If ans = "Miss" Or ans = "Mr" Or ans = "Ms" Or ans = "Mrs"
Then
MsgBox "Please input an appropriate title", vbOKOnly +
vbCritical, "Incorrect Input"
Application.Run "InputMe"
Exit Sub
End If
ActiveCell.Offset.Range("A1") = ans


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA IF statements

Joanne,

You can do a

If var < value Then

so if you want to test for something other than the list you give then

If ans < "None" Then

as an example

You can also use Like

If ans Like "M*" Then

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Joanne Toone" wrote in message
...
I was wondering if you can do an if statement that says "if input isn't
.. then ...". Below is the code im trying to sort out, and i think
you'll understand once you see it!

ActiveCell.Offset(0, 1).Range("A1").Select
ans = Application.InputBox("Enter the customer title: ", _
"Customer Title", Type:=2) ' Type 2 for a text entry
If ans = "Miss" Or ans = "Mr" Or ans = "Ms" Or ans = "Mrs"
Then
MsgBox "Please input an appropriate title", vbOKOnly +
vbCritical, "Incorrect Input"
Application.Run "InputMe"
Exit Sub
End If
ActiveCell.Offset.Range("A1") = ans


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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 statements Pippa Excel Discussion (Misc queries) 1 May 30th 08 02:11 PM
IF Statements (Mutliple Statements) Deezel Excel Worksheet Functions 3 October 19th 06 06:13 AM
using if statements LAybar Excel Worksheet Functions 4 March 20th 06 02:55 PM
if statements qwerty_2006 Excel Worksheet Functions 3 March 12th 06 08:09 AM
IF and OR statements Loraloo Excel Discussion (Misc queries) 3 March 4th 06 11:42 PM


All times are GMT +1. The time now is 03:53 PM.

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

About Us

"It's about Microsoft Excel"