Number Format

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
How should numbers be formatted so that VBA code will recognize any leading or trailing zeros?

For example, I have a list of locations, each with a unique 4-digit location number. But, some of these start with zero, whereas some start with any other number between 1 and 9.

Right now when I type the center number into a text box and hit a button, it performs code I've written, but I want to make sure the user always types in the 4 digit number, even if it means they type in 0123 instead of just 123. This way in case there is a 1123 or 2123 or any other string with a '123' somewhere in it, it ensures they are finding the right record.

Thoughts?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I have the exact situation and have formatted the values as Text so that Excel will recognize the leading zero (or zeroes). If you want to check what a user enters you can code it to check whether Len(EnteredCode) > 3. If they enter a 3-digit code (or less), you can have the code force them to re-enter it.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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