JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,687
- Office Version
- 365
- Platform
- Windows
I need to step thru a range of cells in a Sub setting the fill to either red or green depending on whether the contents are less than or greater than 0.
Using the macro recorder and information from MSDN, I came up with this:
It fails on the Range statement with "Invalid or unqualified reference".
If I change the Range statement to
Then it fails on the If .value statement with "Object doesn't support this property or method".
Can someone help me with the correct syntax to get this to work?
Using the macro recorder and information from MSDN, I came up with this:
Code:
Const Col1 As Long = 3
Const Col2 As Long = 6
Const Row As Long = 22
Dim Col As Long
For Col = Col1 To Col2
Range(.Cells(Row, Col), .Cells(Row, Col)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
If .Value > 0 Then
.color = 65280
Else
.color = 255
End If
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Next Col
It fails on the Range statement with "Invalid or unqualified reference".
If I change the Range statement to
Code:
Range("C22:F22").Select
Then it fails on the If .value statement with "Object doesn't support this property or method".
Can someone help me with the correct syntax to get this to work?