LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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







 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the fill color of a cell cquintero57 Excel Discussion (Misc queries) 2 December 11th 07 04:20 PM
Changing Fill color choices Steven Excel Discussion (Misc queries) 4 March 2nd 05 04:05 AM
Changing cell fill color as result of 'if' statement jason Excel Programming 0 August 31st 03 04:51 PM
Changing cell fill color as result of 'if' statement Tom Ogilvy Excel Programming 0 August 31st 03 04:25 PM
Changing cell fill color as result of 'if' statement Phobos Excel Programming 0 August 31st 03 12:41 PM


All times are GMT +1. The time now is 05:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"