Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2005, 08:42 AM
Authorized User
 
Join Date: Sep 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default alternating colours

Hi,

I am producing quite a lengthy excel report. To aid in pleasant viewing, I would like to alternate background-colorss for the rows.

could someone help me out with the syntax for working out if a number is a whole number or not? i want to do it so that if the row number divided by 2 is a whole number, use one colour, otherwise use another.

secondly, this is a basic question - i am only a newbie at vba... how do I use RGB colours for a row? Is that possible? or do you have to stick with excels choice?

Visit my site: http://www.drybonesuk.com
__________________
Visit my site: http://www.drybonesuk.com
 
Old October 5th, 2005, 10:10 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sub mdl_AlternateLineColours()
Dim myLastRow As Integer
Dim myRow As Integer

Range("A1").Select
myLastRow = Range("a65000").End(xlUp).Row
myRow = 0

Do Until myRow = myLastRow
    myRow = myRow + 1
    If Int(myRow / 2) = myRow / 2 Then
         ActiveCell.Offset(myRow - 1, 0).EntireRow.Interior.ColorIndex = 6
    Else
         ActiveCell.Offset(myRow - 1, 0).EntireRow.Interior.ColorIndex = 35
    End If
Loop

End Sub

cheers

Matt

 
Old October 5th, 2005, 10:18 AM
Authorized User
 
Join Date: Sep 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

wow thanks for that. in the end I had a brainwave after stumbling across the mod function, and as I was counting line by line anyway, I just added the following in the loop:

Code:
If (rowSummary Mod 2) <> 0 Then
        .Range("A" & rowSummary & ":Q" & rowSummary).Interior.ColorIndex = 19
        .Range("A" & rowSummary & ":Q" & rowSummary).Interior.Pattern = xlSolid
End If
thanks for your reply anyway.

Visit my site: http://www.drybonesuk.com
 
Old October 5th, 2005, 10:19 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ActiveCell.Offset(myRow - 1, 0).EntireRow.Interior.Color = RGB(255, 0, 0) ' Return the value for Red.

see the VB help for all the different values of RGB

cheers

Matt






Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternating colors in table crabjoe Classic ASP Basics 3 March 12th, 2007 09:28 AM
Alternating Colors in ListBox rows nkrust ASP.NET 1.0 and 1.1 Basics 2 January 10th, 2007 03:27 PM
Alternating Colors in ListBox rows nkrust ASP.NET 1.0 and 1.1 Professional 1 January 10th, 2007 09:47 AM
system colours DarrenMelling Pro VB 6 3 December 7th, 2006 06:22 AM
Button Colours interrupt Javascript How-To 7 August 26th, 2004 04:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.