Hi1
Mytotal1 shows "45"
cell value shows 45
Cells(x, MyCl).Value = Mytotal1
how do i convert text to number
itried
Cells(x, MyCl).text = Mytotal1
run time error 1004 unable to set the text property in range class
Printable View
Hi1
Mytotal1 shows "45"
cell value shows 45
Cells(x, MyCl).Value = Mytotal1
how do i convert text to number
itried
Cells(x, MyCl).text = Mytotal1
run time error 1004 unable to set the text property in range class
TryCode:Cells(x, MyCl).text = Val(Mytotal1)
in excel, you can not set the text property of a cell, only the value or formula
the code you are using should convert the text string to a number in the cell, unless the cell is formatted as text
to explicitly, convert text to a number, depending on the usage, you can use val, cint, cdbl, ccur, or some others
what is the exact problem you are having?
Set the cell value and cell formatting appropriately.
Mytotal1 has screen value that is showing what everthe value in there for example "191"
as text
when i compare if cells(x,Mycl).value = Mytotal1
technically it matcehs 191 = "191"
but still it exitthe iff statment becasue the cell has val Mytotal 1has text formate
Cells(x, MyCl).text = Mytotal1
i don't know what the problem is you are getting as this should work fine
is the value of the cell calculated by formula?vb Code:
Dim mytot As String mytot = "121" 'string Range("c3").Value = 121 'value MsgBox Range("c3") = mytot 'true
that is more likely to be an issue
Perhaps the cell was formatted as Text before the value is applied.
You need to reformat the cell to "General" or "Number" BEFORE setting its value.
Cells(x, MyCl).Text is read-only property.Code:Cells(x, MyCl).NumberFormat = "General" '-- or "#,##0" or any valid number format
Cells(x, MyCl).Value = Mytotal1
Thanks for everybody its working great.