A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Automatically color merged cells



 
 
Thread Tools Display Modes
  #1  
Old November 11th, 2009, 05:02 PM posted to microsoft.public.excel.misc
Rick
external usenet poster
 
Posts: 727
Default Automatically color merged cells

Using Excel '07, I'm trying to automatically highlight a list of vertically
merged cells the same color as their unmerged rows next to them. For example:

Column A might have cells A2-A5 merged, while cells B2-B5 are not. I'd like
the entire row(s) all the same color, and the next merged set a different
color (A6-A7 merged, with B2-B7 not). Is this possible to do automatically?
Automatic table formatting will unmerge cells in column A and alternately
color each individual row. I would like the groups of rows to each be
colored differently.

Thanks
  #2  
Old November 11th, 2009, 07:25 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default Automatically color merged cells

You mean like banding--red, yellow, red, yellow, red, yellow????

If yes, then you could use something like:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim myColor As Long

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "a").End(xlUp).Row

iRow = FirstRow
myColor = 3
Do
If iRow LastRow Then
Exit Do
End If

.Cells(iRow, "A").MergeArea.EntireRow.Interior.ColorIndex = myColor

iRow = iRow + .Cells(iRow, "A").MergeArea.Rows.Count

If myColor = 3 Then
myColor = 6
Else
myColor = 3
End If
Loop
End With
End Sub

If you don't like those colors, record a macro when you change the fill to
colors that you do like and substitute them in the code (4 places!).



Rick wrote:

Using Excel '07, I'm trying to automatically highlight a list of vertically
merged cells the same color as their unmerged rows next to them. For example:

Column A might have cells A2-A5 merged, while cells B2-B5 are not. I'd like
the entire row(s) all the same color, and the next merged set a different
color (A6-A7 merged, with B2-B7 not). Is this possible to do automatically?
Automatic table formatting will unmerge cells in column A and alternately
color each individual row. I would like the groups of rows to each be
colored differently.

Thanks


--

Dave Peterson
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:10 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.