PDA

View Full Version : Solved: Left Function on Object



Emoncada
03-15-2013, 02:42 PM
I am trying to get the first value of an object.value and determine if it's a "0".

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

This keeps giving me an error of "Run-time error: 438"

Any ideas ?

SamT
03-15-2013, 06:51 PM
You are Concatenating strings and decimals. Try this:
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

mikerickson
03-16-2013, 10:29 PM
Do you need to branch?

ws.Cells(iRow, 3).Value = Val(wd.OLEObjects("TxtItem").Object.Value)

SamT
03-16-2013, 10:54 PM
I think he's trying to insure that TextItem starts with zero.

But then he converts it to a decimal?

Aflatoon
03-18-2013, 03:38 AM
I think it's just a typo of OLEObject versus OLEObjects

Emoncada
03-18-2013, 07:10 AM
I need to make sure TextItem starts with a zero, if it doesn't I need to add the "0".

Aflatoon
03-18-2013, 07:46 AM
If Left(wd.OLEObject("TxtItem").Object.Value, 1) <> "0" Then
should have been:
If Left(wd.OLEObjects("TxtItem").Object.Value, 1) <> "0" Then

snb
03-18-2013, 01:45 PM
sub M_snb()
- - - - -
ws.Cells(iRow, 3) = format(wd.TxtItem.Text,"00")
end sub

mikerickson
03-18-2013, 03:49 PM
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".)

Emoncada
03-19-2013, 09:45 AM
Thanks everybody Aflatoon actually got it right i was missing the "s" in OLEObjects

Thanks again