ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Converting cells from text to number format (https://www.excelbanter.com/excel-programming/380947-re-converting-cells-text-number-format.html)

Ron de Bruin

Converting cells from text to number format
 
Hi fbagirov

You can use the Left function to test the first character

You can try somthing like this
If there are spaces in the cells you must use the trim function also

Sub test()
Dim cell As Range
For Each cell In Range("A1:A10")
If Left(cell.Value, 1) = "0" Then
'do nothing
Else
cell.Value = cell.Value * 1
End If
Next cell
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"fbagirov" wrote in message ...
I get a file with a column with numbers, where the cells are formated as text
to preserve the first 0.
I need to write a macro, that will select the column, and convert all cells
to Number format. In addition, if there is a 0 in front of the number, I want
it to keep the cell in the text format and go to the next cell.

How do I write a code ? Thanks!


fbagirov

Converting cells from text to number format
 
It works great!

Although I replaced Range ("A1:A10") with Selection.

Thanks!

"Ron de Bruin" wrote:

Hi fbagirov

You can use the Left function to test the first character

You can try somthing like this
If there are spaces in the cells you must use the trim function also

Sub test()
Dim cell As Range
For Each cell In Range("A1:A10")
If Left(cell.Value, 1) = "0" Then
'do nothing
Else
cell.Value = cell.Value * 1
End If
Next cell
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"fbagirov" wrote in message ...
I get a file with a column with numbers, where the cells are formated as text
to preserve the first 0.
I need to write a macro, that will select the column, and convert all cells
to Number format. In addition, if there is a 0 in front of the number, I want
it to keep the cell in the text format and go to the next cell.

How do I write a code ? Thanks!




All times are GMT +1. The time now is 10:58 AM.

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