Format Looping

C

Crauwf

Hi all,

I'm trying to set up a code - a loop whereby every time the value of cells
(x,3) changes the cell pattern changes alternately from being shaded in grey
and no colour. Not sure how to write it so that it does what i need.

So for example if i had a s/s with

John
John
Jim
Jim
Jim
Fred

It would colour john cells in Grey shading, Jim - no colour shading and Fred
Grey Shading again.

Sheets("Sheet1").Select

x = 3

Do Until Cells(x, 3).Value = ""

If Cells(x, 3).Value = Cells(x - 1, 3).Value and ...... Then

.....
x = x + 1

Else if cells(

Can anyone help?

Thanks.
 
R

RadarEye

Hi Crauwf,

In Excel 2003 I have created this:

Sub toggleFillColor()
Dim x As Long
Dim b As Boolean

' remove fillcolor
Range("C:C").Interior.ColorIndex = xlNone
x = 2
b = False

Do Until IsEmpty(Cells(x, 3))
If Cells(x, 3).Value <> Cells(x - 1, 3).Value Then
b = Not b
End If
If b Then
With Cells(x, 3).Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If
x = x + 1
Loop
End Sub

HTH,

Wouter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top