Hi there,
I am just after a little help to finish my attempt of automating a conditional format that I use often. I use it to check to different columns of data to see if they are identical or not.
This is my code below.
Currently I have managed to get it somewhat there but the range values are just input as text in when the conditional formatting box is checked. I also do not know how to get the top cell referenced for two different selections.
WHAT I NEED: =OR(AND(A1<>B1,B1<>"),AND(B2<>B1,B1<>"))
WHAT I HAVE WITH CODE SO FAR: =OR(AND(rng1a<>rng2a,rng2a<>"),AND(rng2a<>rng1a,rng1a<>"))
Any help is appreciated.
Cheers,
Milos
I am just after a little help to finish my attempt of automating a conditional format that I use often. I use it to check to different columns of data to see if they are identical or not.
This is my code below.
Sub Conditional_Formatting_MatchData()
Dim rng1, rng1a, rng2, rng2a As Range
Dim DefaultRange1, DefaultRange2 As Range
Dim FormatRuleInput As String
'RANGE1 Determine a default range based on user's Selection
If TypeName(Selection) = "Range1" Then
Set DefaultRange1 = Selection
Else
Set DefaultRange1 = ActiveCell
End If
'RANGE1 Get A Cell Address From The User to Get Number Format From
On Error Resume Next
Set rng1 = Application.InputBox( _
Title:="Check range 1", _
Prompt:="Select a cell range to check against second range", _
Default:=DefaultRange1.Address, _
Type:=8)
On Error GoTo 0
If rng1 Is Nothing Then Exit Sub
'Need to reference top of FIRST selection rng1a = Selection.Cells(1, 1).Select
'RANGE2 Determine a default range based on user's Selection
If TypeName(Selection) = "Range2" Then
Set DefaultRange2 = Selection
Else
Set DefaultRange2 = ActiveCell
End If
'RANGE2 Get A Cell Address From The User to Get Number Format From
On Error Resume Next
Set rng2 = Application.InputBox( _
Title:="Check range 2", _
Prompt:="Select a cell range to check against second range", _
Default:=DefaultRange2.Address, _
Type:=8)
On Error GoTo 0
If rng2 Is Nothing Then Exit Sub
'Need to reference top of SECOND selection rng2a = Selection.Cells(1, 1).Select
'FINAL define the rule for each conditional format
With rng1
.FormatConditions.Add Type:=xlExpression, Formula1:="=OR(AND(rng1a<>rng2a,rng2a<>""),AND(rng2a<>rng1a,rng1a<>""))"
.FormatConditions(1).Interior.ColorIndex = 46
End With
End Sub
End With
End Sub
Currently I have managed to get it somewhat there but the range values are just input as text in when the conditional formatting box is checked. I also do not know how to get the top cell referenced for two different selections.
WHAT I NEED: =OR(AND(A1<>B1,B1<>"),AND(B2<>B1,B1<>"))
WHAT I HAVE WITH CODE SO FAR: =OR(AND(rng1a<>rng2a,rng2a<>"),AND(rng2a<>rng1a,rng1a<>"))
Any help is appreciated.
Cheers,
Milos