我正在尝试将一个工作表中的 2 列与另一个工作表中的 2 列(或可能更多)进行匹配。
我已经发布了我的工作表数据样本,希望能很好地描述我过去一周一直在尝试做的事情。我认为我在正确的轨道上,但我不知道如何在两个工作表之间正确引用。
我想做的是查看位置 1 列,然后查看该位置是否与位置 1 或位置 2 中的我的 RefSheet 引用。
如果是这样,我想看看位置 2 是否在 RefSheet 的同一行的某处匹配。如果匹配,我想突出显示单元格/单元格黄色并提供 RefSheet 中的 ID 号。
如果没有匹配,我想将其突出显示为红色或不突出显示。
Sheet All
A B C D
ID Location 1 Location 2 Given ID
1 West North
2 North South
3 South East
4 East West
5 East East
6 South West
Sheet RefSheet
A B C
ID Location 1 Location 2
1 West North
2 West East
3 South East
4 South North
What it should look like on the original Worksheet
A B C D
ID Location 1 Location 2 Given ID
1(Yellow) West North 1
2(Yellow) North South 4
3(Yellow) South East 3
4(Yellow) East West 2
5(Red) East East
6(Red) South West
这是我可怕的代码
Sub roadfinder()
Dim lngLast As Long
Dim lngCounter As Long
Dim rCell As Range
Dim lCnt As Long
Dim nextIntersection
Dim RefSheet As Worksheet
Dim list As Worksheet
Set intersections = ThisWorkbook.Sheets("RefSheet")
Set crashes = ThisWorkbook.Sheets("All")
Application.ScreenUpdating = False
lngLast = Cells(Rows.Count, "B").End(xlUp).Row
For lngCounter = 2 To lngLast
With Cells(lngCounter, "B")
For Each rCell In RefSheet.Range("B1", RefSheet.Cells(RefSheet.Rows.Count, 1)).Cells
lCnt = lCnt + 1
'I wasn't sure what to put as a reference to
If .Value = "" Then
.Interior.ColorIndex = 6
End If
Next rCell
End With
Next lngCounter
Application.ScreenUpdating = True
End Sub