Consulting

Results 1 to 15 of 15

Thread: Solved: Range.Find question - Max length "What:=" string can be

  1. #1
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location

    Solved: Range.Find question - Max length "What:=" string can be

    Having a problem with using the Range.Find method. I have other ways of doing what I want to do, but it made me curious to know if there is a limit to the "What" parameter of the Range.Find method.

    Here was the code that failed because of a "Type Mismatch" (which makes me think that it's not the amount of text in the what.....but I can't think of anything else):

    [vba]Set cell = ContractorWS.Range("A1", ContractorWS.Cells.SpecialCells(xlCellTypeLastCell).Address) _
    .Find(What:=txtPackage.Text, LookIn:=xlValues)[/vba]
    And here's the text:
    Up to 84 L.F. (15' x 30'), 3' to 5' depth, bullnose, standard tile, 1.0 HP, C-900, 4' swimout, dedicated vac-line; +12" raised Spa, 2 pump system, 4 function air switch, 2 HP blower, 75W light, 5 Jets, 24" Spillway, H-155 heat pump; Diamond Brite in White, Ivory, or Blue




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Hi,

    Yes it's the 255 limit. This limit also applies when doing the find manually.

    This is the most text you can search will
    Up to 84 L.F. (15' x 30'), 3' to 5' depth, bullnose, standard tile, 1.0 HP, C-900, 4' swimout, dedicated vac-line; +12" raised Spa, 2 pump system, 4 function air switch, 2 HP blower, 75W light, 5 Jets, 24" Spillway, H-155 heat pump; Diamond Brite in White
    You should load the cells content in to a variable and then truncate that to 255.
    The use find with the relatively short text
    Cheers
    Andy

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You could search for the first 255 characters, then search the found cells for the next 255 and so on.......
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Cool, thanks guys.


    As far as my coding goes...I realized that there are cases where more than one cell with the same text (my example being one of them I believe). I realized that even if I could use more than 255 characters, I may still have errors. So I went another route...




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    A tourist stopped an Irishman to ask for directions to Dublin. "Well", said the worthy man, "If I were you, I wouldn't start from here!"
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I wouldn't trust the xlCellTypeLastCell either...

    [vba]Dim LastCell as Long
    LastCell = ContractorWS.Range("A:A").Find("*", after:=ContractorWS.Cells(1, 1), _
    lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlprevious).row
    Set cell = ContractorWS.Range("A1:A" & LastCell).Find(What:=txtPackage.Text, _
    LookIn:=xlValues)[/vba]

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You'd have thought someone with 3,000+ posts would have come across line breaks!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    ROFL! There!

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks Zack, I'll cancel my order for a 42" wide screen.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by firefytr
    I wouldn't trust the xlCellTypeLastCell either...
    Why not?




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  11. #11
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Sometimes Excel gets it scewed up. Do you have ASAP Utilities? There is a function in there to reset Excel's LastCell. The input/output (deletion) of data will *confuse* Excel sometimes. Using the Find("*") method is probably the most sure way to get the last row with data.

  12. #12
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Thanks Zack. Always helps to know a more efficient way of coding / working




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  13. #13
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    No problem Joseph. Keep in mind, there are some who disagree with me, that is my (trying to be humble) opinion, albeit a strong one.

  14. #14
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by firefytr
    Keep in mind, there are some who disagree with me
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  15. #15
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Okay, okay, call me the black sheep of the bunch. I'm young/dumb and I voice my opinion. Hehehe.

Posting Permissions

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