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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,216,081
Messages
6,128,696
Members
449,464
Latest member
againofsoul

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