+ Reply to Thread
Results 1 to 5 of 5

Find multiple values in multiple ranges and produce results in a list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Find multiple values in multiple ranges and produce results in a list

    Hi Guys and Gals of Excel Forum, I have an interesting dilemma and I'm not quite sure where to start looking for answers (or even if there is an answer).

    I'd like to carry out a find all search for occurrences of a combination of someones surname and post code (columns 12 & 13 respective) in the same worksheet, then for all occurrences of this combination I would like the result value of column 2 to be listed in a separate sheet.

    i.e.e
    Find = Jones & 18/11/1977

    then say we find 4 results the list in another sheet to read

    12345
    23456
    34567
    45678

    Is this do-able?

  2. #2
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Find multiple values in multiple ranges and produce results in a list

    Can you use autofilter and just copy and paste the filtered values to another sheet?
    otherwise, you may need a Macro
    Click on the star if you think I helped you

  3. #3
    Registered User
    Join Date
    02-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Find multiple values in multiple ranges and produce results in a list

    Just tried this and it works



    Sub find_all()
    Dim strName As String, strCode As String
    Dim lngResultPoint As Long
    Dim firstaddress As String
    Dim c
            
        ''pointer to the first cell where the data will be written
        lngResultPoint = 1
        ''set the name being searched
        strName = "name to search"
        ''set the postcode
        strCode = "code to search"
        
        ActiveSheet.Range("L:L").Select
        
        With Selection
            Set c = .Find(What:=strName)
            If Not c Is Nothing Then
                firstaddress = c.Address
                Do
                    If c.Offset(0, 1).Value = strCode Then
                        Worksheets("Results").Cells(lngResultPoint, 1).Value = c.Offset(0, -10).Value
                        lngResultPoint = lngResultPoint + 1
                    End If
                    
                    Set c = .FindNext(c)
                Loop While c.Address <> firstaddress
            End If
        End With
            
    
    End Sub

  4. #4
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: Find multiple values in multiple ranges and produce results in a list

    You Star, adapted for my purposes and works like a charm.

    I'd be interested to know how to incorporate an additional search criteria though, say name, DOB and then post code (in that order)?

  5. #5
    Registered User
    Join Date
    02-09-2014
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Find multiple values in multiple ranges and produce results in a list

    This is simple but it works

    Sub find_all()
    Dim strName As String, strCode As String, strDOB As String
    Dim lngResultPoint As Long
    Dim firstaddress As String
    Dim c
            
        ''pointer to the first cell where the data will be written
        lngResultPoint = 1
        ''set the name being searched
        strName = "name to search"
        ''set the postcode
        strCode = "code to search"
        ''set the DOB
        strDOB = "DOB to search"
        
        ActiveSheet.Range("L:L").Select
        
        With Selection
            Set c = .Find(What:=strName)
            If Not c Is Nothing Then
                firstaddress = c.Address
                Do
                    ''##A simple option is to check both criteria on the same line
                    If c.Offset(0, 1).Value = strCode And c.Offset(0, 2).Value = strDOB Then ''Replace column 2 with one which should contain the DOB
                    
                        Worksheets("Results").Cells(lngResultPoint, 1).Value = c.Offset(0, -10).Value
                        lngResultPoint = lngResultPoint + 1
                    
                    End If
                    
                    ''OR
                    ''##you could nest them
                    If c.Offset(0, 2).Value = strDOB Then ''Replace column 2 with one which should contain the DOB
                        If c.Offset(0, 1).Value = strCode Then
                        
                            Worksheets("Results").Cells(lngResultPoint, 1).Value = c.Offset(0, -10).Value
                            lngResultPoint = lngResultPoint + 1
                        
                        End If
                    End If
                    
                    Set c = .FindNext(c)
                Loop While c.Address <> firstaddress
            End If
        End With
            
    
    End Sub

+ 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. Produce multiple results after searching a value
    By Stagnant in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2013, 06:55 AM
  2. [SOLVED] Double-click macro to produce different results based on different cell ranges
    By Hobsons in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-06-2013, 07:28 AM
  3. Replies: 2
    Last Post: 05-10-2012, 10:38 AM
  4. Naming multiple name ranges in a long list of excel values in one sheet
    By melancholic93 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2012, 11:21 PM
  5. Replies: 3
    Last Post: 01-16-2006, 02:10 AM

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