The LoadRunner Blog

Monday, October 03, 2016

Pattern Matching Macro for Excel



Sub LookUpMatch()
    Dim wsLookup As Worksheet
    Dim wsMatch As Worksheet
    Set wsLookup = Sheets("LookUp")
    Set wsMatch = Sheets("Master")

    Dim LastRow As Long
    Dim RecordCount As Long
    LastRow = 1
   
    wsMatch.Activate
    LastRow = wsMatch.Range("A" & Rows.Count).End(xlUp).Row + 1
 
 
    wsMatch.Range("a1", wsMatch.Range("a1").End(xlDown)).Select
           
   
    For Each c In Selection.Cells
       
    sRaw = c.Value
           
        'Select wsLookUp.A range
        'Loop through each value to see if inStr matches.
        'If InStr Matches, Select original cell
        'In next cell add "I"
        'Loop
        'MsgBox sRaw
        wsLookup.Activate
        wsLookup.Range("a1", wsLookup.Range("a1").End(xlDown)).Select
       
        For Each d In Selection.Cells
        sLookUp = d.Value
        TestPos = InStr(LCase(sRaw), LCase(sLookUp))
       
        If TestPos > 0 Then
           
            MsgBox "Found " & sLookUp & " in " & sRaw
       
       
        Exit For
        End If
           
       
        Next d
       
       
    Next c
   
   
   
MsgBox ("All Done")
End Sub

0 Comments:

Post a Comment

<< Home