Consulting

Results 1 to 10 of 10

Thread: Solved: Left Function on Object

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    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 ?

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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]

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Do you need to branch?

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

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I think he's trying to insure that TextItem starts with zero.

    But then he converts it to a decimal?

  5. #5
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I think it's just a typo of OLEObject versus OLEObjects
    Be as you wish to seem

  6. #6
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    I need to make sure TextItem starts with a zero, if it doesn't I need to add the "0".

  7. #7
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    [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]
    Be as you wish to seem

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    [VBA]
    sub M_snb()
    - - - - -
    ws.Cells(iRow, 3) = format(wd.TxtItem.Text,"00")
    end sub
    [/VBA]

  9. #9
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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".)

  10. #10
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    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
  •