retrieve custom format text instead of general text?

R

Rich

I have a column of numbers that range from 5 to 10 digits
in length for each number. This column is general
format. Each cell in this column needs to contain a
uniform string length of 10. So I format the column as
custom 0000000000, with leading zeroes.

Selection.NumberFormat = "0000000000"

Ideally, this would now be text data instead of numbers.
But if I loop through this column as follows,
------------------------------------
Dim rng as range, i as integer
Set rng = Range("A1:A10")
For i = 1 to rng.rows.count
debug.print rng(i, 1)
Next
-----------------------------------
I am reading the original numbers without the leading
zeroes. The question is "how can I read the data in this
column with the custom format instead of the general
format? Could I set the custom format as I retrieve the
general formatted data? Or do I have to format the column
as text and add the leading zeroes using string
manipulation?

Thanks,
Rich
 
R

Rich

OK. Here is what I did which worked:

Columns("D:D").NumberFormat = "@"
Set rng = Range("d2:d38")
For i = 1 To rng.Rows.Count
rng(i, 1) = Format(rng(i, 1), "0000000000")
Next
For i = 1 To rng.Rows.Count
Debug.Print rng(i, 1)
Next

I then read the data into sql server and now the
numbers/text are/is coming in as nvarchars instead of
floats.
 

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