Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 5th, 2005, 08:42 AM
Authorized User
 
Join Date: Sep 2003
Location: , , United Kingdom.
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
Reply With Quote
  #2 (permalink)  
Old October 5th, 2005, 10:10 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Bournemouth, Dorset, United Kingdom.
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

Reply With Quote
  #3 (permalink)  
Old October 5th, 2005, 10:18 AM
Authorized User
 
Join Date: Sep 2003
Location: , , United Kingdom.
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
Reply With Quote
  #4 (permalink)  
Old October 5th, 2005, 10:19 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Bournemouth, Dorset, United Kingdom.
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:39 AM.


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