Consulting

Results 1 to 4 of 4

Thread: Type mismatch error

  1. #1
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location

    Type mismatch error

    Hello,

    I get a type mismatch error when writing this line of code. I'm doing something wrong and I can't figure it out. ! Please can someone point out my mistake. Thanks.

    [vba] Range("A:A").Find(What:="My Tables", After:=ActiveCell, LookIn:=xlFormulas _
    , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Select [/vba]

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Might need a little more info.
    Peace of mind is found in some of the strangest places.

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Seems like if you put "My Tables" in a cell in column A it clears it up. Did at least for me. Using the quotes around the string made the error go away.
    Peace of mind is found in some of the strangest places.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    It only works if the ActiveCell is in Col A. I think it was the After:=ActiveCell

    If "My Tables" is not found, then you'll get an error when you try to select it

    [VBA]
    Sub drv()
    Dim r As Range
    Set r = Range("A:A").Find(What:="My Tables", LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
    If Not r Is Nothing Then r.Select
    Set r = Range("A:A").Find(What:="Not There", LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
    If Not r Is Nothing Then r.Select

    End Sub
    [/VBA]

    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •