Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 May 12th, 2006, 02:28 PM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel VBA Background Color

I am trying to use VBA to fill cells with a color starting at a certain date going forward. For example, I have data in the format below:

Year 1 2 3 4 5 6 7 8 9 10 11 12
2006 x x x y y
2005 x x

The x's represent available (which will change for different examples) data while the y's represent cells that I want to fill in with any color (again the range will change with differnet examples). Therefore, in this case, I only want to fill April 2006 to May 2006 (represented by today).

I am not a programmer so I am not sure what the next steps are.
 
Old May 12th, 2006, 02:41 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I'm not sure exactly what you are looking for, but hopefully the following code I used for another project will be of some help.

I linked this to a button click and used it to color a range of cells, based on their values. Hopefully it will help steer you in the right direction.

arrCells is an array of the Cell Columns "C" through "AW" or something.
dbNil, dbPoorLow, dbFairLow and dbGood are values that I set elsewhere to compare against.
intNul, intPoor, intFair and intGood are integers holding the various color numbers.

Public Sub colorCells()

    For intRow = 9 To 15
        If intRow = 12 Then
            intRow = 13
        End If
        For intCol = 3 To 40
            Range(arrCells(intCol) & intRow).Select
            dblNumber = Val(Selection.Text)
            If dblNumber < dblNil Then
                Selection.Interior.ColorIndex = intNil
            End If
            If dblNumber >= dblPoorLow And dblNumber < dblPoorHigh Then
                Selection.Interior.ColorIndex = intPoor
            End If
            If dblNumber >= dblFairLow And dblNumber < dblFairHigh Then
                Selection.Interior.ColorIndex = intFair
            End If
            If dblNumber >= dblGood Then
                Selection.Interior.ColorIndex = intGood
            End If
        Next intCol
    Next intRow
End Sub

Mike

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
change color of background meena88 C# 2005 3 December 1st, 2009 04:48 AM
Background Color matrix ArnieStewart BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 3 October 21st, 2008 01:12 AM
mdi-background color avats General .NET 1 February 28th, 2008 10:25 AM
background-color disappears harpua CSS Cascading Style Sheets 1 August 19th, 2005 04:53 PM
Get stylesheet's background color muklee Javascript How-To 2 October 31st, 2004 08:03 AM





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