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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm very near a solution for form 1

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
330
GB

I'm very near a solution for formatting a range of cells in a worksheet created from Access

This colours alternate rows but does the entire rows, not just the parts in the specified range.

Code:
    Dim LR As Long, i As Long
    'Find the last filled row in column A
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    'Loop through the filled rows in steps of 2
    For i = 2 To LR Step 2
        Rows(i).EntireRow.Interior.ColorIndex = 15
    Next i

How do I limit to the columns in the range?
 
Code:
For i = 2 To LR Step 2
    Range("A" & i & ":G" & i).Interior.Color = 15
Next i

This question would be better to ask in forum707 [wiggle]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 

Thanks for this, did the job perfectly. It needed Interior.ColorIndex not Color, otherwise it filled alternate rows with black.
I'd used the Microsoft Office forum and didn't have the one you suggested on the 'My Forums' list, but do now.
 
Macro recorder in Excel is your friend. :)
Just Start recording, do your step(s) 'by-hand' of what you want to happen, and stop recording.
[tt]Alt-F11[/tt] will show you the code created. It is a very good starting point of coding in Excel's VBA

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top