CreativeUsername
Board Regular
- Joined
- Mar 11, 2017
- Messages
- 52
Hi,
I need to reference a cell in Column A and B on the Active row for a conditional formatting command and am having trouble.
It isn't the most glorious bit of code but it works with the exception that its hard coded to reference A2 and B2. Rather I need A and ActiveCell.row or ActiveCell.Offset. I'm not hitting it right with the syntax apparently and I don't find an example online to emulate.
My code is below. It selects a horizontal range of dates and colors any that fall between the date range in formula section.
What am I doing wrong?
This COULD be structured to check each cell in the range F2 to AC2 to the bottom (xldown) BUT the items is 27K rows long... so I prefer to minimize cell by cell manipulations.
thanks
I need to reference a cell in Column A and B on the Active row for a conditional formatting command and am having trouble.
It isn't the most glorious bit of code but it works with the exception that its hard coded to reference A2 and B2. Rather I need A and ActiveCell.row or ActiveCell.Offset. I'm not hitting it right with the syntax apparently and I don't find an example online to emulate.
My code is below. It selects a horizontal range of dates and colors any that fall between the date range in formula section.
What am I doing wrong?
Code:
Sub Conditions()
'
' Conditional format
Dim x As Integer
Application.ScreenUpdating = False
NumRows = Range("F2", Range("F2").End(xlDown)).Rows.Count
'Range("F2").Select
'Range(("F2"), Selection.End(xlToRight)).Select
Range("F2").Select
Range(("F2"), Selection.End(xlToRight)).Select '<------------Start row segment selection here.
For x = 1 To NumRows
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=$A$2", Formula2:="=$B$2"
'Formula1:=ActiveCell.Offset(0,5), Formula2:=ActiveCell.Offset(0,4) '<---- offset from active cell
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
ActiveCell.Offset(1, 0).Select
Range(ActiveCell, ActiveCell.End(xlToRight)).Select
Next
Application.ScreenUpdating = True
End Sub
This COULD be structured to check each cell in the range F2 to AC2 to the bottom (xldown) BUT the items is 27K rows long... so I prefer to minimize cell by cell manipulations.
thanks
Last edited by a moderator: