+ Reply to Thread
Results 1 to 9 of 9

Use .Cells.Find(What:=) to find values in Multiple Cells

  1. #1
    Forum Contributor
    Join Date
    12-19-2012
    Location
    Woodbridge, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    111

    Use .Cells.Find(What:=) to find values in Multiple Cells

    All,

    I am currently using the .Cells.Find method to put values into my userform. It does well finding one specific value in a cell but I can't figure out how to get this method to look at two values in two different cells. For example, I would like it to do the following:

    If column B = sFind value and column C = sFind2 value, then pull the values from that row into the userform.

    Can anyone please help? I've looked everywhere and can't seem to find the solution that I am looking for.

    Thank you in advance for your help.


    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    This link explains it well. See the "What if I want to search for multiple occurrences of an item" section

    The ultimate search
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-02-2012
    Location
    Michigan
    MS-Off Ver
    2010
    Posts
    11

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    If you need a certain value to be in two different cells in the same row, I would start at the top and move down one row at a time until you get to the row you need.

    Please Login or Register  to view this content.
    This is just what I would try, but someone else might have a better suggestion.

  4. #4
    Registered User
    Join Date
    08-02-2012
    Location
    Michigan
    MS-Off Ver
    2010
    Posts
    11

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    Quote Originally Posted by AlphaFrog View Post
    This link explains it well. See the "What if I want to search for multiple occurrences of an item" section

    The ultimate search
    Using information from the article that AlphaFrog referred to, we can create a much more efficient search loop than the one I initially suggested. The below set of code uses the FindNext method to loop through all instances of strFind in Column 2 and for each one tests whether the cell in Column 3 of that same row also contains strFind.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-19-2012
    Location
    Woodbridge, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    111

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    Thank you so much AlphaFrog and MenacingBanjo! I will take a look and get back to you with my results. Thank you again!!

  6. #6
    Forum Contributor
    Join Date
    12-19-2012
    Location
    Woodbridge, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    111

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    Thank you again for your help with this issue. I just noticed that the code is looking for strFind in column 2 and in column 3. I think I should have explained my situation more clearly but what I am looking for is to look up strFind in column B and then in column C, look for integers 1 - 6. For example, column B is the change form # which is generated by taking the user's First and Last Name Initials + Today's Date and Time ex: JH051320140933 and in column C, the values would be 1 - 6 depending on the line item. The first line item is 1 which every record should have but if there are more line items, then the next row would have the same change form # (JH051320140933) in column B but in column C, the line item would be 2. The max line items is 6.

    Please let me know your thoughts on this. Can I still apply the .Cells.Find method?

    Thank you again!
    Last edited by s2jrchoi; 05-13-2014 at 10:06 AM.

  7. #7
    Registered User
    Join Date
    08-02-2012
    Location
    Michigan
    MS-Off Ver
    2010
    Posts
    11

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    Quote Originally Posted by s2jrchoi View Post
    I just noticed that the code is looking for strFind in column 2 and in column 3. I think I should have explained my situation more clearly but what I am looking for is to look up strFind in column B and then in column C...
    If I'm not mistaken Column 2 and Column 3 are the same columns as B and C.
    If you need to find "JH051320140933" in Column B, and a certain integer in Column C, then use the same code as above except instead of looking for strFind in Column 3, you look for whatever integer you need. In the example below, I used the number 1.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    I don't mean to be overly critical MenacingBanjo, but there are a couple of flaws in your code.

    Wrong syntax
    Set rngFind = .Cells(1, 2).EntireColumn.Find(strFind) is Nothing Then

    Do Until rngFind is Nothing Or rngFind.Address = strFirstAddress
    Before the Do-Loop begins, rngFind.Address does equal strFirstAddress so the loop never runs

    If the loop were to run, the "Required" variables are set after all the .Find matches are found. So the variables will only equal the last match. s2jrchoi has not explained what to do with each .Find match.

    With dataSheet

    dataSheet is not declared or defined. Maybe your assuming s2jrchoi is doing that earlier in the code?

  9. #9
    Forum Contributor
    Join Date
    12-19-2012
    Location
    Woodbridge, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    111

    Re: Use .Cells.Find(What:=) to find values in Multiple Cells

    All,

    Thank you for your help. I got it to work but I got the help from AlphaFrog's link because I did notice a few flaws in MB's code.

    Please Login or Register  to view this content.
    Thank you again!! I will mark this as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Find values from cells in multiple sheets
    By asubramaniam in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  2. [SOLVED] Find values from cells in multiple sheets
    By asubramaniam in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  3. Find values from cells in multiple sheets
    By asubramaniam in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  4. Find values from cells in multiple sheets
    By asubramaniam in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  5. Find values from cells in multiple sheets
    By asubramaniam in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

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