vba create text format cells in excel 2003

  • Thread starter Thread starter douglas
  • Start date Start date
D

douglas

I need to put char(5) into 'selected' columns in an excel 2003 worksheet
using VBA.
The problem is some of the data looks like '00123' and ends in the
spreadsheet looking like '123'. I am losing the leading zeroes. The only way
I know to make the selected range of columns is to make the selected columns
a 'text' format.
Thus using VBA can you tell me how to do the solve the problem above:
1. Do I set the selected columns to 'text' fomrat and then input the
data? If not,
2. Do I put data into the selected columns and then change the data to a
'text' format?

Thanks!
 
Range("A1").NumberFormat = "@"
Range("A1") = 10

OR
Dim lngTemp As Long
lngTemp = 10
Range("A1").NumberFormat = "@"
Range("A1") = Format(lngTemp, "0000")

If this post helps click Yes
 
what does Range("A1").NumberFormat = "@" mean?

Jacob Skaria said:
Range("A1").NumberFormat = "@"
Range("A1") = 10

OR
Dim lngTemp As Long
lngTemp = 10
Range("A1").NumberFormat = "@"
Range("A1") = Format(lngTemp, "0000")

If this post helps click Yes
 
Back
Top