How to handle input box error

jakeman

Active Member
Joined
Apr 29, 2008
Messages
325
Office Version
  1. 365
Platform
  1. Windows
Hey guys - I have an inputbox in my macro that will prompt a user to enter a 3 month character for 1 of 12 months: Jan, Feb, Mar, etc. If the user doesn't type a value or most importantly, incorrectly types the month character like Jam instead of Jan, I want an error handler that will notify the user to try again.

Here's part of the code that I've been working on:

Code:
monthValue = InputBox("Which month do you want to transpose data for?  Enter Jan or Feb or Mar using 3 letter character for month.") ' this is the month that user wants to transpose data

If monthValue <> "Jan" Or "Feb" Or "Mar" Or "Apr" Or "May" Or "Jun" Or "Jul" Or "Aug" Or "Sep" Or "Oct" Or "Nov" Or "Dec" Then

msgbox "Please try again and enter a correct month."
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If monthValue <> "Jan" Or "Feb" Or "Mar" Or "Apr" Or "May" Or "Jun" Or "Jul" Or "Aug" Or "Sep" Or "Oct" Or "Nov" Or "Dec" Then
You need to change all your "Or" statements to "And", and you need a complete statement for each one, like this:
Code:
If (monthValue <> "Jan") And (monthValue <> "Feb") And (monthValue <> "Mar") And ...
 
Upvote 0
Thanks, Joe. That helped get me where I wanted to be.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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