Results 1 to 8 of 8

Macro not finding partial matches

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,408

    Macro not finding partial matches

    User enters either a First Name in D4, Family Name in D6 or Project in Col D9 of the Input Form

    For this example Database has variations on two Project names in Col C, but the "real" file can also have variations in First or Family Names.

    Need Macro to search each Database row. If it finds a record with a partial or whole match to whatever is in Col D, it should copy the Data to the next free row from L4 downwards.

    Unfortunately it isn't doing it, but I can't see why.

    Option Explicit
    Dim e As Long, f As Long, x As Long
    
    Sub FINDMATCHES()
    
        With Sheet2
        f = .Cells(.Rows.Count, "A").End(xlUp).Row
        End With
        
        e = 4
        
        With Sheet1
        
        For x = 3 To f
       
            If InStr(1, .Range("D4").Value, Sheet2.Range("A" & x).Value, vbTextCompare) > 0 Then
            .Range("L" & e) = Sheet2.Range("D" & x)
            .Range("M" & e) = Sheet2.Range("A" & x)
            .Range("N" & e) = Sheet2.Range("B" & x)
            .Range("O" & e) = Sheet2.Range("C" & x)
            e = e + 1
            
            ElseIf InStr(1, Sheet1.Range("D6").Value, Sheet2.Range("B" & x).Value, vbTextCompare) > 0 Then
                    
            .Range("L" & e) = Sheet2.Range("D" & x)
            .Range("M" & e) = Sheet2.Range("A" & x)
            .Range("N" & e) = Sheet2.Range("B" & x)
            .Range("O" & e) = Sheet2.Range("C" & x)
            e = e + 1
                            
            ElseIf InStr(1, Sheet1.Range("D9").Value, Sheet2.Range("C" & x).Value, vbTextCompare) > 0 Then
            .Range("L" & e) = Sheet2.Range("D" & x)
            .Range("M" & e) = Sheet2.Range("A" & x)
            .Range("N" & e) = Sheet2.Range("B" & x)
            .Range("O" & e) = Sheet2.Range("C" & x)
            e = e + 1
            
            ElseIf InStr(1, Sheet2.Range("D9").Value, Sheet2.Range("D" & x).Value, vbTextCompare) > 0 Then
            .Range("L" & e) = Sheet2.Range("D" & x)
            .Range("M" & e) = Sheet2.Range("A" & x)
            .Range("N" & e) = Sheet2.Range("B" & x)
            .Range("O" & e) = Sheet2.Range("C" & x)
            e = e + 1
            
            End If
            
            Next
           
        End With
           
    End Sub
    Any suggestions, pointers, solutions or alternatives welcomed as ever.

    Ochimus
    Attached Files Attached Files
    Last edited by Ochimus; 04-21-2018 at 01:37 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Comparing two data sets and finding matches or non matches
    By b0bertini in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-18-2017, 09:34 AM
  2. Find Partial matches
    By KTM450 in forum Excel General
    Replies: 11
    Last Post: 11-05-2015, 10:09 PM
  3. [SOLVED] Multiple partial matches
    By Grinfactor in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-28-2014, 01:15 PM
  4. [SOLVED] Finding partial text matches compared to a range
    By grifta67 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-17-2014, 04:38 PM
  5. Finding dupllicates using partial matches
    By cmax979 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2013, 09:52 PM
  6. Finding Partial String Matches
    By evs in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-02-2009, 06:22 AM
  7. [SOLVED] Autofiltering for partial matches
    By PeterJordan in forum Excel General
    Replies: 1
    Last Post: 01-12-2006, 05:35 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