Data validation and formatting using vba

end_debug

New Member
Joined
Mar 11, 2015
Messages
1
Hello,

I'm creating a user form in excel. I have one cell in which the inputted data needs to conform to strict guidelines (it's an account number field). What I'd like to do is use vba to validate the cell content immediately after it is entered (e.g. as soon as focus is shifted away from the cell), and if it passes validation, it should be formatted in a specific way:
  1. The cell should contain exactly 9 characters (or 10 if a dash is entered, see step 4) If not, a message should be displayed notifying the user and focus placed back on the offending cell
  2. The first 3 characters can be alphanumeric, the last 6 must be numeric. If not, a message should be displayed notifying the user and focus placed back on the offending cell)
  3. Any alpha characters within the first 3 should then be made uppercase
  4. A dash "-" should be inserted between the first 3 and last 6 if not already present (it should not exist anywhere else in the string)

Any questions please let me know, and THANK YOU in advance for your assistance!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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