【发布时间】:2015-07-20 20:46:13
【问题描述】:
我希望能够比较两个工作表,如果 ws1 上的 H 列和 ws2 上的 F 列中的日期存在差异,则突出显示 ws2 上的单元格。我遇到的问题是它们是两个不同的列,从两个不同的单元格开始(比较 ws1 上的 H9+ 和 ws2 上的 F10+) 这没有给我任何错误,但似乎什么也没发生。这是我目前所拥有的:
Sub matchMe()
Dim wS As Worksheet, wT As Worksheet
Dim r1 As Range, r2 As Range
Dim cel1 As Range, cel2 As Range
Set wS = ThisWorkbook.Worksheets("Project Status Report L3")
Set wT = ThisWorkbook.Worksheets("Demand Mapping - Active")
With wS
Set r1 = .Range("H9", .Cells(.Rows.Count, .Columns("R:R").Column).End(xlUp))
End With
With wT
Set r2 = .Range("F10", .Cells(.Rows.Count, .Columns("G:G").Column).End(xlUp))
End With
On Error Resume Next
For Each cel1 In r1
With Application
Set cel2 = .Index(r2, .Match(cel1.Value, r2, 0)) 'find match in sheet2
If Err = 0 Then
If cel1.Offset(, 8) <> cel2.Offset(, 8) Then cel2.Interior.ColorIndex = 1 'if difference, color
End If
Err.Clear
End With
Next cel1
结束子
【问题讨论】:
-
为什么不用Find method 而不是
.Index?