Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interior Colouring used cells in a Row 1

Status
Not open for further replies.

VickyC

Technical User
Sep 25, 2010
206
0
0
CA
hi - I'm totally new to Excel VBA. I've need code to copy the tables in a set of worksheets into Sheets(1). All works perfectly.

But, I now want to fill the header row cells of each table using, say, colorindex = 37.

As I loop through Sheets(2) to the end, I run the following code fragment...

Code:
Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(3)
Sheets(1).Range("A65536").End(xlUp)(-29).Interior.ColorIndex = 37

The first line works perfectly, copying each table below the previous one. My problem is how to do the coloring of the header rows of each table.

My 2nd line of code above work, BUT ONLY in column A. In each table, I need to color from A to Q.

Any help for this newbie is appreciated!
Vicky
 
Hi,

First a technical issue that could have an impact further down the road. 65536 is the number of rows in Excel version 2003 I believe. A better way of specifying the last row in a sheet is Cells.Rows.Count.

Now to your issues. "My problem is how to do the coloring of the header rows of each table."

Your code seems to indicate that you're stacking these tables one under another with two rows separating each. Am I correct?

Okay, here's a solution, but I have serious questions regarding the approach that you're using. 1) I wouldn't be using Selection.Copy, 2) I definitely wouldn't be stacking tables.
Code:
'
    With Sheets(1)
        Selection.Copy Destination:=.Cells(.Cells.Rows.Count, "A").End(xlUp).Offset(2)
        With .Cells(.Cells.Rows.Count, "A").End(xlUp).CurrentRegion
            Range(.Cells(1, "A"), .Cells(1, "A").End(xlToRight)).Interior.ColorIndex = 37
        End With
    End With


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
thanks, Skip, for a quick response, and for the advice.
Vicky
 
Can you explain what you're attempting to accomplish with this stacking approach?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top