Hello itsnick,
Here is a preliminary workbook. The results that match are copied onto the "Results" worksheet. There is a command button on this sheet to run the macro. Here is the macro...
Sub MatchData()
Dim Cell As Range
Dim DBWks As Worksheet
Dim DstWks As Worksheet
Dim Key As Variant
Dim Keys As Variant
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim Znums As Object
R = 1
Set DBWks = Worksheets("Database")
Set DstWks = Worksheets("Results")
Set Znums = CreateObject("Scripting.Dictionary")
Znums.CompareMode = vbTextCompare
Set RegExp = CreateObject("VBScript.RegExp")
RegExp.Pattern = "(\w\d{8})(\d{2})"
Set Rng = Worksheets("List").Range("A1")
Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row > Rng.Row, Rng.Parent.Range(Rng, RngEnd), Rng)
For Each Cell In Rng
Key = Trim(Cell.Text)
If Key <> "" Then
If Not Znums.Exists(Key) Then Znums.Add Key, ""
End If
Next Cell
Set Rng = DBWks.Range("A1")
Set RngEnd = DBWks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row > Rng.Row, DBWks.Range(Rng, RngEnd), Rng)
DstWks.Cells.ClearContents
C = DBWks.Cells(1, Columns.Count).End(xlToLeft).Column
For Each Cell In Rng
X = RegExp.Test(Cell.Text)
If RegExp.Test(Cell.Text) Then
Key = Trim(RegExp.Replace(Cell.Text, "$1" & "00"))
If Znums.Exists(Key) Then
DstWks.Cells(R, "A").Resize(1, C) = Cell.EntireRow.Value
R = R + 1
End If
End If
Next Cell
Set Znums = Nothing
Set RegExp = Nothing
End Sub
Bookmarks