+ Reply to Thread
Results 1 to 10 of 10

Find Text VBA code

  1. #1
    Forum Contributor
    Join Date
    10-27-2009
    Location
    San Diego California
    MS-Off Ver
    Excel 2010
    Posts
    160

    Find Text VBA code

    The following VBA code allows me to type in cell A6 what I want to find in the sheet. Right now it searches the whole sheet, how can I narrow the search to a range and match exactly what is in A6. I have tried editing line 2 with a range and line 4 in a couple ways and can't get it.

    Please Login or Register  to view this content.
    I have tried the following to narrow the range and find exact match

    first attempt on line 3 of original code
    Please Login or Register  to view this content.
    second attempt on line 3 of original code
    Please Login or Register  to view this content.
    After these attempts and returning the code to the original, the whole process breaks down and won't search anywhere in the sheet, The return just goes to A11.

    Any suggestions, this sheet searches for the location of a truck among 767 entries, I would also like to expand to VIN and license # searches, hence the exact match attempt.
    please see attached file.
    Attached Files Attached Files
    Last edited by MARKSTRO; 08-31-2011 at 02:47 PM. Reason: adding code tags

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Find Text VBA code

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Find Text VBA code

    Hello,

    I think that it is because .Find method gives you only first Match after Target.
    You should use some loop and method .FindNext. (Collect match addresses in colleciton or in range union)
    I will think about some example for you.

    Best Regards
    MaczaQ

  4. #4
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Find Text VBA code

    So I discover a way

    please try following code
    Please Login or Register  to view this content.
    Best Regards
    MaczaQ

  5. #5
    Forum Contributor
    Join Date
    10-27-2009
    Location
    San Diego California
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Find Text VBA code

    Still no joy, when I press return after entering the search text the return goes to cell A12.
    How do I attach the latest sheet in a reply for you to look at?

  6. #6
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Find Text VBA code

    use "Go Advanced" or "New Post" as a replay then attach document

  7. #7
    Forum Contributor
    Join Date
    10-27-2009
    Location
    San Diego California
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Find Text VBA code

    Thanks, see attached.
    It seems the code will work a couple of times then stop working, not sure if I have a setting set wrong or lose something when I save/quit and then reopen the file.
    Hope you can make this work for me, I thought I would have it solved by now on my own.
    thanks,
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Find Text VBA code

    better solution then previous one, just init it with search value in your code (example. LookingFor "abcd")

    Please Login or Register  to view this content.
    Best Regards

  9. #9
    Forum Contributor
    Join Date
    10-27-2009
    Location
    San Diego California
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Find Text VBA code

    Do I insert A7 as my search box for the A1 references in line 2?

  10. #10
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Find Text VBA code

    You can do this for select "A7" when nothing is found
    But previously you should refer to this procedure when Target (A7) is changed

    for example:
    Please Login or Register  to view this content.
    Best Regards
    MaczaQ

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1