Hi All,
I’m writing a procedure to convert numbers to text because I use accounting data downloaded to Excel from our accounting system, and sometimes the 5-digit account numbers come over as text and other times they download as numbers. I need a routine that will make them consistent so that they’ll work in vlookup functions.
I came across the following macro that seems to do the job, but I don’t understand the cell.Value = CStr(Temp) line; what is CStr?
Also, some of the procedures I came across prefixed the cell contents with an apostrophe. What’s the difference between setting a cell’s value to text like in the procedure below and prefixing it with an apostrophe?
Thanks for the help!
Sub NumToText()
' Convert the selected Excel numbers value to Excel text by changing format
For Each cell In Selection
If Not IsEmpty(cell.Value) And IsNumeric(cell.Value) Then
Dim Temp As Double
Temp = cell.Value
cell.ClearContents
cell.NumberFormat = "@"
cell.Value = CStr(Temp)
End If
Next cell
End Sub
I’m writing a procedure to convert numbers to text because I use accounting data downloaded to Excel from our accounting system, and sometimes the 5-digit account numbers come over as text and other times they download as numbers. I need a routine that will make them consistent so that they’ll work in vlookup functions.
I came across the following macro that seems to do the job, but I don’t understand the cell.Value = CStr(Temp) line; what is CStr?
Also, some of the procedures I came across prefixed the cell contents with an apostrophe. What’s the difference between setting a cell’s value to text like in the procedure below and prefixing it with an apostrophe?
Thanks for the help!
Sub NumToText()
' Convert the selected Excel numbers value to Excel text by changing format
For Each cell In Selection
If Not IsEmpty(cell.Value) And IsNumeric(cell.Value) Then
Dim Temp As Double
Temp = cell.Value
cell.ClearContents
cell.NumberFormat = "@"
cell.Value = CStr(Temp)
End If
Next cell
End Sub