# Alternate Cell shading

#### jlangella36

##### New Member
Is there an easy way to shade every other cell based on the data within the cell.

for example.

1 - shade grey
1 - shade grey
1 - shade grey
1 - shade grey
2
2
3 - shade grey
4
4
4
5 - shade grey
5 - shade grey
5 - shade grey
5 - shade grey
6
7 - shade grey
8

this needs to be done for thousands of records and will be sort on the name, it wont be numbers, i just used that as an example, there will be at least 100 unique records, so would be hard to program.

thanks,

Jeff

### Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I have not used it much but the free ASAP add in has a few shading tools that are easy to use

Ben

If you want every other row shaded using Conditional Formatting, highlight your range, go to Format/Conditional Formatting and Formula is, condition 1

=MOD(ROW(),2)=0

condition 2

=MOD(ROW(),2)=1

try this
Code:
``````Sub yui()
r = 2
1:
Do While Not IsEmpty(Cells(r, 1))
Do While Cells(r, 1) = Cells(r + 1, 1)
Cells(r, 1).Interior.ColorIndex = 15
r = r + 1
Loop
Cells(r, 1).Interior.ColorIndex = 15
r = r + 1

Do While Cells(r, 1) = Cells(r + 1, 1)
Cells(r, 1).Interior.ColorIndex = xlNone
r = r + 1
Loop
Cells(r, 1).Interior.ColorIndex = xlNone
r = r + 1
GoTo 1
Loop

End Sub``````

thanks pcc,

that worked great, it came up with a runtime error, but overall it worked.

thanks again,

Jeff

jlangella36

Welcome to the Mr Excel board!

For a Conditional Formatting solution as shown below.

1. Select A2:A??
2. Format|Conditional Formatting...|Formula Is:
=MOD(SUMPRODUCT(--(A\$1:A1<>A\$2:A2)),2)
3. Click Format... and choose colour
4. OK, OK
Mr Excel 05 11 20.xls
ABCD
1Fred
2Fred
3Jan
4Jan
5Jan
6Sam
7Sam
8Ann
9Bill
10Bill
11Bill
12Sue
13Sue
14
Conditional Format

Replies
5
Views
214
Replies
7
Views
453
Replies
19
Views
154
Replies
8
Views
276
Replies
0
Views
961

Threads
1,216,172
Messages
6,129,291
Members
449,498
Latest member
Lee_ray

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

### Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

### Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back