Susan said:
Thanks for the replies. It looks like recording a macro while using Excel's
conditional formatting only generates coding for the formatting I'm after, so
I guess I didn't frame my question particularly well.
The coding I'm struggling with has to do with the VBA logic and application
of the formats. I didn't include any of my VBA in the original post because I
suspect I'm pretty far off target. Here are a few of the things I've tried so
far:
Example 1:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 22 And Target.Column <> 23 And Target.Column <> 15
Then Exit Sub 'Column O is 15, Column V is 22, Column W is 23
If Target.Row = 1 Then Exit Sub
'
Application.EnableEvents = False
If Target.Column = 22 Then
If Target.Offset(0, 0) = "Internal" And Target.Offset(0, 1) =
"Internal" Then Target.EntireRow.Interior.ColorIndex = 40 Else
Target.EntireRow.Interior.ColorIndex = x1colorindexautomatic
End If
If Target.Column = 23 Then
If Target.Offset(0, 0) = "Internal" And Target.Offset(0, -1) =
"Internal" Then Target.EntireRow.Interior.ColorIndex = 40 Else
Target.EntireRow.Interior.ColorIndex = x1colorindexautomatic
End If
If Target.Column = 15 Then
If Target.Offset(0, 0) >= 1 And Target.Offset(0, -1) = "" Then
Target.EntireRow.Font.ColorIndex = 10 Else Target.EntireRow.Font.ColorIndex =
x1colorindexautomatic
If Target.Offset(0, 0) = "RET" And Target.Offset(0, -1) = "RET" Then
Target.EntireRow.Font.ColorIndex = 15 Else Target.EntireRow.Font.ColorIndex =
x1colorindexautomatic
If Target.Offset(0, 0) = "RET" And Target.Offset(0, -1) >= 1 Then
Target.EntireRow.Font.ColorIndex = 3 Else Target.EntireRow.Font.ColorIndex =
x1colorindexautomatic
End If
Application.EnableEvents = True
End Sub
Example 2:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngControl As Range
Dim rngVisibility As Range
Dim rngIT18 As Range
Dim rngIT19 As Range
Dim rngExposure As Range
Set rngControl = Target.Column("V")
Set rngVisibility = Target.Column("W")
Set rngIT18 = Target.Column("N")
Set rngIT19 = Target.Column("O")
Set rngExposure = Target.Column("T")
If rngControl = "Internal" And rngVisibility = "Internal" Then
Target.EntireRow.Interior.ColorIndex = 40 Else
Target.EntireRow.Interior.ColorIndex = x1colorindexautomatic
If rngIT18 = "RET" And rngIT19 = "RET" Then
Target.EntireRow.Font.ColorIndex = 48 Else Target.EntireRow.Font.ColorIndex =
x1colorindexautomatic
If rngIT18 = "" And rngIT19 = "RET" Then
Target.EntireRow.Font.ColorIndex = 10 Else Target.EntireRow.Font.ColorIndex =
x1colorindexautomatic
If rngIT18 >= 1 And rngIT19 = "RET" Then
Target.EntireRow.Font.ColorIndex = 3 Else Target.EntireRow.Font.ColorIndex =
x1colorindexautomatic
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Static myoldcell
If myoldcell = Empty Then
myoldcell = ActiveCell.Address
End If
If Range(myoldcell).Row = 1 Or Range(myoldcell).Column = 1 Or
ActiveCell.Count > 1 Then
Exit Sub
End If
If Application.IsNumber(Range(myoldcell).Offset(0, 1)) = True And
Range(myoldcell) = "" And Range(myoldcell).Column = 14 Then
Range(myoldcell).EntireRow.Font.Color = RGB(50, 140, 70)
Else
Range(myoldcell).EntireRow.Font.ColorIndex = 1
End If
If Application.IsNumber(Range(myoldcell)) = True And
Range(myoldcell).Offset(0, -1) = "" And Range(myoldcell).Column = 15
Then
Range(myoldcell).EntireRow.Font.Color = RGB(50, 140, 70)
End If
If Application.IsNumber(Range(myoldcell).Offset(0, 1)) = False And
Range(myoldcell) = "" And Range(myoldcell).Column = 14 Then
Range(myoldcell).EntireRow.Font.ColorIndex = 1
End If
If Application.IsNumber(Range(myoldcell)) = False And
Range(myoldcell).Offset(0, -1) = "" And Range(myoldcell).Column = 15
Then
Range(myoldcell).EntireRow.Font.ColorIndex = 1
End If
If Range(myoldcell) = "RET" And Range(myoldcell).Offset(0, 1) = "RET"
And Range(myoldcell).Column = 14 Then
Range(myoldcell).EntireRow.Font.Color = RGB(130, 130, 130)
'Else: Range(myoldcell).EntireRow.Font.ColorIndex = 1
End If
If Range(myoldcell) = "RET" And Range(myoldcell).Offset(0, -1) = "RET"
And Range(myoldcell).Column = 15 Then
Range(myoldcell).EntireRow.Font.Color = RGB(130, 130, 130)
'Else: Range(myoldcell).EntireRow.Font.ColorIndex = 1
End If
If IsNumeric(Range(myoldcell)) = True And Range(myoldcell).Offset(0, 1)
= "RET" And Range(myoldcell).Column = 14 Then
Range(myoldcell).EntireRow.Font.Color = RGB(200, 20, 10)
End If
If Range(myoldcell) = "RET" And IsNumeric(Range(myoldcell).Offset(0,
-1)) = True And Range(myoldcell).Column = 15 Then
Range(myoldcell).EntireRow.Font.Color = RGB(200, 20, 10)
End If
If Range(myoldcell) = "internal" And Range(myoldcell).Offset(0, -1) =
"internal" Then
Range(myoldcell).EntireRow.Interior.ColorIndex = 40
ElseIf Range(myoldcell) = "" Then
Range(myoldcell).EntireRow.Interior.ColorIndex = xlNone
End If
If Range(myoldcell) = "internal" And Range(myoldcell).Offset(0, 1) =
"internal" Then
Range(myoldcell).EntireRow.Interior.ColorIndex = 40
ElseIf Range(myoldcell) = "" Then
Range(myoldcell).EntireRow.Interior.ColorIndex = xlNone
End If
If Range(myoldcell) < 1 And Range(myoldcell) > 0.000001 And
Range(myoldcell).Offset(-1, 0) >= 1 And Range(myoldcell).Column = 20
Then
Application.EnableEvents = False
Range(myoldcell).EntireRow.Select
With Selection.Borders(xlEdgeTop)
..LineStyle = xlContinuous
..Weight = xlThick
..ColorIndex = 5
End With
Application.EnableEvents = True
Range(myoldcell).Offset(2, 0).Select
End If
If Range(myoldcell) > 1 And Range(myoldcell).Offset(-1, 0) >= 1 And
Range(myoldcell).Column = 20 Then
Set rng = ActiveSheet.Range(myoldcell).EntireRow
rng.Borders.LineStyle = xlNone
End If
myoldcell = ActiveCell.Address
End Sub
Cheers Christian