View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] jseger22@yahoo.com is offline
external usenet poster
 
Posts: 4
Default changing the fill color on a cell

Hi,

I am trying to fill the color of a cell based on if statements, but I
don't know how to reference the cell. Everything works except when I
try to reference the CellValue to fill the cell and I am not sure what
I am doing wrong because I am only a novice at VBA. My code looks
like

Sub Macro2()
Dim lastyear As Double
Dim target As Double
Dim CellValue As Double
Dim i As Integer

For i = 5 To 15

CellValue = Cells(i, 37)
target = Cells(i, 3) * 100
lastyear = Cells(i, 25)


If CellValue = lastyear And CellValue = target Then
CellValue.Interior.ColorIndex = 4
ElseIf CellValue = lastyear And CellValue < target Then
CellValue.Interior.ColorIndex = 3
ElseIf CellValue < lastyear And CellValue < target Then
CellValue.Interior.ColorIndex = 6
Else
CellValue.Interior.ColorIndex = 3
End If
Next
End Sub