Validate variable from InputBox is either "A" or "B"

jardenp

Active Member
Joined
May 12, 2009
Messages
373
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2011
  5. 2010
Platform
  1. Windows
I am using an InputBox to ask for variable AcctSelect. I want to set up a simple If Then statement to test if AcctSelect is either 1) "A" or "B" or 2) something else and then exit sub. I need to use the variable later for column selection and anything other than "a" or "b" would throw an error. Case is not important. Something like this, with the red parts replaced by actual code that does what's described:
Code:
dim AcctSelect as String
AcctSelect =  InputBox("Enter A or B")

IF [COLOR=#ff0000](AcctSelect = "A" OR AcctSelect = "B") [/COLOR]Then[INDENT]Range("A1").Select[/INDENT]
Else 
[INDENT]MsgBox "Please rerun macro and enter ""A"" or ""B"""
Exit Sub[/INDENT]
End If
Also, I know I could loop it back to the InputBox, but I'd like it to exit the sub if it's neither "A" nor "B" (again, if it matters, it's not case-sensitive).

Thanks!

Josh in IN
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Have you put brackets around this for our benefit or are they really there? if so remove them
 
Upvote 0
You want us here in the forums to fix the red text by turning it into "Actual code". That is what I think you are asking. The problem is that it is actual code. Nothing needs to get fixed. You did it all by yourself. gj
 
Upvote 0
Wow. Yeah, I was just trying to communicate what I wanted and that's the code (minus brackets)? That's never happened. Thanks, Dryver14 and WarPigl3t! I must be a natural!
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top