+ Reply to Thread
Results 1 to 8 of 8

VBA Search within a given range

  1. #1
    Registered User
    Join Date
    12-23-2008
    Location
    Tulsa, Oklahoma
    MS-Off Ver
    2007
    Posts
    4

    VBA Search within a given range

    Hello, thank you for looking.

    I have the following code:

    Please Login or Register  to view this content.
    .... Other States in Code with basically the same code, just differing range values.


    After which there are more ElseIf statements that are dependent on the state. My problem is this; each county is not unique to every state and rather than going through and modifying every single non-unique county name, I'd rather just search through a given range of values... which I thought I did (i.e. rngLook) which I update for each ElseIf. County(n) is a loaded array as string, as well as Area(n) and RR(n). County(n) should be the only variable effecting the search. However, when I run the code it just grabs the last county of that name on my spreadsheet rather then getting only the county name within the given range. What am I doing wrong?

    Thank you,

    Cody
    Last edited by CodyMartin; 12-29-2008 at 03:51 PM. Reason: Forum noob, my apology.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Welcome to the forum, Cody.

    Please take a few minutes to read the Forum Rules, and then edit your post to wrap your code with Code Tags.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    If you just want to search within rngLook you need to amend to:
    Please Login or Register  to view this content.
    The full stop before Find references rngLook.

  4. #4
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    In your Set rngFound line you are having the code look at all the cells on the sheet not just those in rngLook

    try something like
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    HTH

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Cody,

    Thanks for the code tags.

    bhofsetz,

    The syntax in both of your statements is wrong; try it.

    Stephen,

    Yours is fine (as you know), but doesn't make clear that After needs to be a cell in the Find range, and you should always specify LookIn and SearchOrder (in addition to MatchByte) lest they default to prior values:
    Please Login or Register  to view this content.
    Last edited by shg; 12-23-2008 at 07:47 PM.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Thank you shg. Remiss of me, I saw one error and stopped looking.

  7. #7
    Registered User
    Join Date
    12-23-2008
    Location
    Tulsa, Oklahoma
    MS-Off Ver
    2007
    Posts
    4
    Thank you very much shg, bhofsetz, and StepherR, my problem is now solved! This portion of my program works perfectly (and much more efficiently). I appreciate the help.

    Regards,

    Cody

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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