我在同一个工作簿中有两个工作表。第一个工作表包含最后一个期间分数矩阵,第二个工作表包含此期间分数矩阵。
我正在努力寻找一个能够在此期间工作表中突出显示与上一期工作表不同的单元格。
我已经能够确定已更改的细胞。我知道这可以使用'MsgBoxes',但我无法找到突出识别出的细胞的方法。这可能是因为我选择完全以错误的方式解决这个问题。有人可以给我一个关于我应该怎么做的指南吗?
我所拥有的代码(根据MsgBox无论如何)如下所示。我非常感谢任何指导。 谢谢,
Option Explicit
Sub B_HighlightDifferences()
'Workbooks("Scoring Matrix NEW").Activate
Dim varScoring As Variant
Dim varScoring_OLD As Variant
Dim strRangeToCheck As String
Dim irow As Long
Dim icol As Long
Dim color As CellFormat
strRangeToCheck = "bl9:bo15" 'smallrange for testing purposes only
varScoring = Worksheets("Scoring").Range(strRangeToCheck)
varScoring_OLD = Worksheets("Scoring_OLD").Range(strRangeToCheck)
For irow = LBound(varScoring, 1) To UBound(varScoring, 1)
For icol = LBound(varScoring, 2) To UBound(varScoring, 2)
If varScoring(irow, icol) = varScoring_OLD(irow, icol) Then
' Cells are identical. ' Do nothing.
MsgBox "This has not changed"
Else
' Cells are different.
' Need code here to highlight each cell that is different
MsgBox "This has changed"
End If
End If
Next icol
Next irow
End Sub
答案 0 :(得分:1)
你做了大部分艰苦的工作。我会改变以下内容。添加:
dim newCell as Range
Application.ScreenUpdating = False
...然后在你的for循环中:
Set newCell = varScoring.Cells(irow, icol)
然后,当您发现它们不同时,您应该能够应用newCell
(Range
对象)所需的任何格式。
newCell.Select
With Selection.Interior
.Color = 49407
' any formatting you want.
End With
在例程结束时,再次打开屏幕更新:
Application.ScreenUpdating = True
如果这是有道理的,请告诉我。