Tim Hanson
Member
My matching code is "not" finding all the matches and finding matches that do not exsits
I think the problem is here
is getting out off sequence
I know there are lots of ways to match, but I was hoping someone can help get this code working
Also I mostly match on text but I have numbers here because it was easy to generate data for testing
I have uploaded a file with data showing the problem
Thanks
I think the problem is here
Code:
PostBackWS.Range(fCell.Address).Offset(0, 0).Interior.Color = RGB(255, 255, 0)
Code:
fCell.Address
I know there are lots of ways to match, but I was hoping someone can help get this code working
Also I mostly match on text but I have numbers here because it was easy to generate data for testing
I have uploaded a file with data showing the problem
Thanks
Code:
Sub sColorMatch()
Dim PostBackWS As Worksheet
Dim FindRng As Range, ReplaceRng As Range, fCell As Range, rCell As Range
Dim lRowFR As Long, lRowRR As Long
Dim t As Date
t = Now()
With ThisWorkbook.Sheets("X")
lRowFR = .Range("A" & .Rows.Count).End(xlUp).Row
Set FindRng = .Range("A2:A" & lRowFR)
End With
With ThisWorkbook.Sheets("Y")
lRowRR = .Range("A" & .Rows.Count).End(xlUp).Row
Set ReplaceRng = .Range("A2:A" & lRowRR)
End With
Set PostBackWS = ThisWorkbook.Sheets("Y")
For Each fCell In FindRng
If DoesMatchExists(fCell, ReplaceRng) = True Then
'Set Interior Color for Matches
PostBackWS.Range(fCell.Address).Offset(0, 0).Interior.Color = RGB(255, 255, 0)
End If
Next fCell
MsgBox Format(Now() - t, "hh:mm:ss")
End Sub
Function DoesMatchExists(ByVal searchName As String, nameRange As Range) As Boolean
Dim i As Long
Dim j As Long
Dim v As Variant
v = nameRange.Value
DoesMatchExists = False
For i = 1 To UBound(v, 1)
For j = 1 To UBound(v, 2)
If v(i, j) = searchName Then
DoesMatchExists = True
Exit Function
End If
Next j
Next i
End Function