Add leading zeros fill space

R

Rob

Hi,

Using Excel 2000

I have spreadsheet that uses text entries to do a Vlookup, the look up range
has text in the format of 6 characters albeit they look like numbers with
leading zeros eg. '000100. The entry that I enter if '000100 returns the
correct result. However, when others enter they tend to just enter '100
which doesn't match. I therefore thought that if I could check the length
of their entry, I could fill with leading zeros to make it 6 characters
long.

Having tried to do this with validation, I'm now thinking this is a change
cell piece of code.

Any pointers of sample code would be appreciated.

Thank you, Rob
 
G

Guest

using a worksheet function

=REPT(0,6-LEN(A1))&A1

using VBA

Sub test()

num = 100
longstr = String(6 - Len(A1) & A1, "0")
End Sub
 
B

Bob Phillips

=VLOOKUP(REPT("0",6-LEN(A1))&A1,L1:p9,2,FALSE)

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top