-
Solved: Left Function on Object
I am trying to get the first value of an object.value and determine if it's a "0".
[VBA] If Left(wd.OLEObject("TxtItem").Object.Value, 1) <> "0" Then
ws.Cells(iRow, 3).Value = "0" & CDec(wd.OLEObjects("TxtItem").Object.Value)
Else
ws.Cells(iRow, 3).Value = CDec(wd.OLEObjects("TxtItem").Object.Value)
End If[/VBA]
This keeps giving me an error of "Run-time error: 438"
Any ideas ?
-
You are Concatenating strings and decimals. Try this:
[VBA]If Left(wd.OLEObject("TxtItem").Object.Value, 1) <> "0" Then
ws.Cells(iRow, 3).Value = CDec("0" & wd.OLEObjects("TxtItem").Object.Value)
Else
ws.Cells(iRow, 3).Value = CDec(wd.OLEObjects("TxtItem").Object.Value)
End If [/VBA]
-
Do you need to branch?
[VBA]ws.Cells(iRow, 3).Value = Val(wd.OLEObjects("TxtItem").Object.Value)[/VBA]
-
I think he's trying to insure that TextItem starts with zero.
But then he converts it to a decimal?
-
I think it's just a typo of OLEObject versus OLEObjects
-
I need to make sure TextItem starts with a zero, if it doesn't I need to add the "0".
-
[vba]If Left(wd.OLEObject("TxtItem").Object.Value, 1) <> "0" Then [/vba]
should have been:
[vba]If Left(wd.OLEObjects("TxtItem").Object.Value, 1) <> "0" Then [/vba]
-
[VBA]
sub M_snb()
- - - - -
ws.Cells(iRow, 3) = format(wd.TxtItem.Text,"00")
end sub
[/VBA]
-
Are you putting a number or a string in the cell.
(Note: No number ever starts with a 0. Some numerals (strings) do start with a "0".)
-
Thanks everybody Aflatoon actually got it right i was missing the "s" in OLEObjects
Thanks again
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