Phil Payne
Board Regular
- Joined
- May 17, 2013
- Messages
- 131
- Office Version
- 365
- Platform
- Windows
Hello all,
I have two worksheets in the same workbook. The first worksheet contains last periods score matrix, the second worksheet contains this periods score matrix.
I am struggling to find a away to highlight those cells in this periods worksheet that are different from last periods worksheet.
I have been able to go as far as identifying the changed cells. I know that works from use of 'MsgBoxes', however I cannot find a way to highlight the identified cells. Its probably because I have chosen to go about this the wrong way entirely. Can someone please give me a guide as to how I should go about this?
The code I have that works (according to MsgBox's anyway) is below. I would very mush appreciate any guidance whatsoever.
Thanks,
I have two worksheets in the same workbook. The first worksheet contains last periods score matrix, the second worksheet contains this periods score matrix.
I am struggling to find a away to highlight those cells in this periods worksheet that are different from last periods worksheet.
I have been able to go as far as identifying the changed cells. I know that works from use of 'MsgBoxes', however I cannot find a way to highlight the identified cells. Its probably because I have chosen to go about this the wrong way entirely. Can someone please give me a guide as to how I should go about this?
The code I have that works (according to MsgBox's anyway) is below. I would very mush appreciate any guidance whatsoever.
Thanks,
Code:
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
[I] ' Cells are identical. ' Do nothing.[/I]
MsgBox "This has not changed"
Else
[I] ' Cells are different. [/I]
[B]' Need code here to highlight each cell that is different[/B]
MsgBox "This has changed"
End If
End If
Next icol
Next irow
End Sub