Hi there,
I have a conditional formatting macro that works well comparing lists of non-matching data on the same worksheet. What it does fail to do is to also compare data lists on two different worksheets. Is there a way to adjust the code so that it handles selecting data from 2 different worksheets?
Code is posted below.
Thanks in advance,
Milos
I have a conditional formatting macro that works well comparing lists of non-matching data on the same worksheet. What it does fail to do is to also compare data lists on two different worksheets. Is there a way to adjust the code so that it handles selecting data from 2 different worksheets?
Code is posted below.
VBA Code:
Sub Cond_Format_Data_Match()
Dim rng1, rng2 As Range
'RANGE1 Input a range to check against second list
On Error Resume Next
Set rng1 = Application.InputBox( _
Title:="Select List 1", _
prompt:="Select part of a column", Type:=8)
Err.Clear
On Error GoTo 0
If rng1 Is Nothing Then Exit Sub
'RANGE2 Input a range to check against first list
On Error Resume Next
Set rng2 = Application.InputBox( _
Title:="Select List 2", _
prompt:="Select part of a column", Type:=8)
Err.Clear
On Error GoTo 0
If rng2 Is Nothing Then Exit Sub
'Set the conditional format formula
With rng1
.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(" & rng1.Address(0, 0) & "<>" & rng2.Address(0, 0) & ",TRUE,FALSE)"
.FormatConditions(1).Interior.Color = RGB(226, 239, 218)
End With
With rng2
.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(" & rng2.Address(0, 0) & "<>" & rng1.Address(0, 0) & ",TRUE,FALSE)"
.FormatConditions(1).Interior.Color = RGB(226, 239, 218)
End With
End Sub
Thanks in advance,
Milos