![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Location: Melbourne, Australia
Posts: 5
|
I'm using a userform for data entry, which includes a textbox for a numeric code. My problem is that the textbox automatically kills all leading zeros... ie... 0104 will become 104. However i need these leading zeros as the are part of the code. Can anyone help me with this?
Cheers... Daniel |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
|
Hi Daniel,
I hope you are not too dazed. Actually, you must set up the textbox for string input, because numerically there is no difference between 0104 and 104--they are both the value one hundred four. What I would recomend is that right after textbox entry you check the string using the VBA IsNumeric function to ensure that the string represents a legal numeric value. But from that point on, since you want 0104 to be distinct from 104 you must deal with it as a string. The second you convert the code to any numeric type (Integer, Long, Single, Double, etc.) it will lose its "distinctness."
__________________
Keep Excelling. Damon VBAexpert Excel Consulting (My other life: http://damonostrander.com ) |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
You could also try with this code (Which converts the text to a string)
|
|
|
|
|
|
#4 |
|
New Member
Join Date: Feb 2002
Location: Melbourne, Australia
Posts: 5
|
Thanks for your suggestions guys...
Just wondering, how would i set a textbox for string entry only, as opposed to numeric? It there an option somewhere that i can select? Cheers... Dan |
|
|
|
|
|
#5 |
|
New Member
Join Date: Feb 2002
Location: Melbourne, Australia
Posts: 5
|
Don't worry.... i've sorted it... i just set the cells i was putting the data into to be text format and its solved all my worries...
Cheers |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|