View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Stuart[_10_] Stuart[_10_] is offline
external usenet poster
 
Posts: 12
Default Changing color of cells

Worksheets("Yearly Planner").Select
Range("A2:D53").Select
If MsgBox("Do you Work the first weekend?", vbYesNo) = vbYes Then
x = vbBlue
y = vbBlack
Else
x = vbBlack
y = vbBlue
End If

For Each rng In Selection
If Application.Round(rng.Row / 2, 0) - Application.Round(rng.Row / 2, 2) = 0
Then
rng.Font.Color = x
Else
rng.Font.Color = y
End If
Next rng



Carl Brehm wrote in message
...
Need to change color of every other row, but only that portion of row in
the range.
Here is what I have.


Sub working()
Dim x As Integer
Dim response
response = MsgBox("Do you Work the first weekend?", vbYesNo)
If response = vbYes Then
x = 0
Else
x = 1
End If

With Worksheets("Yearly Planner")
For Each cell In .Range("A2:D53")
With cell
If x = 0 Then
.Font.Color = vbBlue ' working weekend
Else
.Font.Color = black 'off weekend
End If
End With

' does Excel go to next cell in row or in column?


Next cell in Row, excel will go through table left to right then down, same
as reading!

But if you are trying to change the colour of font in the whole of the
range, you don't need to do it cell by cell!

try
Sub working()
Worksheets("Yearly Planner").Select
If MsgBox("Do you Work the first weekend?", vbYesNo) = vbYes Then
Range("A2:D53").Font.Color = vbBlue ' working weekend
Else
Range("A2:D53").Font.Color = vbBlack 'off weekend
End If
End Sub






End Sub

Thanks Carl
--
Carl & Linda Brehm
Lake Lafourche Bird House
Hebert, LA
Keets, Tiels, GN & Red Lories, Quakers
Mitred Conures, TAG's,DYH, Bourkes,
Cages, Toys, Toy parts Wholesale/Retail
Feed & Supplies


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.522 / Virus Database: 320 - Release Date: 09/29/2003