range data type

  • Thread starter Thread starter seanw
  • Start date Start date
S

seanw

how do I set a range's data type using VB? I wrote a vb
app to parse data into a csv file. Then I open the csv
into excel and populate the columns. Now I need to set
the columns to text instead of the numbers being treated
like numbers.



thx
 
You don't

you can format a cell, but since your value is already stored there, it will
have no effect.

columns(1).NumberFormat = "@"
formats a column as Text.

To make the numbers text after the fact you would have to do

With Activesheet
for each cell in Intersect(.Columns(1),.UsedRange)
if isnumeric(cell.Value) then
cell.Value = "'" & cell.Value
' or cell.Value = "'" & cell.Text
end if
Next
End With
 
Generally, if you set the format of the cells in the
worksheet to Text and then PasteSpecial Values the CSV
file in, the numbers should format as if they were text.
 

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

Back
Top