VBA to cause alternating colors except for certain cells

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
Hi,

I need to add some vba code to make the rows of columns a , b c , and d alternating colors except for the cells which are already filled with purple (or any color really) since these cells are my headers to my tables in these columns and i do not want them to change fill. Any help?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
So the Macro should only consider the rows AFTER the Header-Column Row(s). What are the start and stop rows of your headers?
 
Upvote 0

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,350
To alternate colors, you could use ConditionalFormatting with either

=(MOD(ROW(),2)=1) (to color alternate rows)

or

=(MOD(ROW()+COLUMN(), 2) = 1) (to make a checker-board)


To preserve your headers, just don't apply CF to those cells.
 
Upvote 0

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
To alternate colors, you could use ConditionalFormatting with either

=(MOD(ROW(),2)=1) (to color alternate rows)

or

=(MOD(ROW()+COLUMN(), 2) = 1) (to make a checker-board)


To preserve your headers, just don't apply CF to those cells.

Yea i was looking for a quick way to do this with vba but I decided to do a different method in my coding to make this happen. Thank you for the suggestion though via worksheet.

Thanks!
 
Upvote 0

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
Can you describe your data set with a bit more detail? What version of Excel are you using? Are you using actual Tables? Can you give an example?

For posting parts of your spreadsheet (which works really well in giving a visual) take a look at this link:
http://www.mrexcel.com/forum/board-announcements/515787-forum-posting-guidelines.html#post2545970


Thank you for that reference, I will be sure to do that next time I have a question. I was able to code it in a way where I controlled the fills much better. I made a dummy sheet which I hide. So I filled the cells with the a random color. Then in the code I mapped my selection to any cells with this color create the alternating fill within there by using a for loop and row Mod 2 with an if statement equal to 0 or not 0 and each having its own color to alternate. Worked great for anyone else need to do alternating colors in on select areas.

Either way thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,195,942
Messages
6,012,428
Members
441,699
Latest member
tnlbado

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

Which adblocker are you using?

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
Top