ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   range data type (https://www.excelbanter.com/excel-programming/307238-range-data-type.html)

seanw

range data type
 
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

Tom Ogilvy

range data type
 
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

--
Regards,
Tom Ogilvy

"seanw" wrote in message
...
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




tod

range data type
 
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.


-----Original Message-----
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
.



All times are GMT +1. The time now is 02:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com