|
-
Mar 18th, 2010, 10:40 AM
#1
Thread Starter
Addicted Member
[RESOLVED] text value convert into number
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
-
Mar 18th, 2010, 11:48 AM
#2
Re: text value convert into number
Try
Code:
Cells(x, MyCl).text = Val(Mytotal1)
-
Mar 18th, 2010, 03:06 PM
#3
Re: text value convert into number
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?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 18th, 2010, 05:17 PM
#4
Re: text value convert into number
Set the cell value and cell formatting appropriately.
-
Mar 18th, 2010, 06:19 PM
#5
Thread Starter
Addicted Member
Re: text value convert into number
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
-
Mar 18th, 2010, 08:54 PM
#6
Re: text value convert into number
i don't know what the problem is you are getting as this should work fine
vb Code:
Dim mytot As String mytot = "121" 'string Range("c3").Value = 121 'value MsgBox Range("c3") = mytot 'true
is the value of the cell calculated by formula?
that is more likely to be an issue
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 19th, 2010, 05:15 AM
#7
Re: text value convert into number
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.
Code:
Cells(x, MyCl).NumberFormat = "General" '-- or "#,##0" or any valid number format
Cells(x, MyCl).Value = Mytotal1
Cells(x, MyCl).Text is read-only property.
-
Mar 19th, 2010, 07:59 AM
#8
Thread Starter
Addicted Member
Re: text value convert into number
Thanks for everybody its working great.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|