Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
 
Posts: n/a
Default conditional formatting autoshapes

I have a cluster of autoshapes (map of a city divided into regions)
that I need to colour according to how much that region spent on
services. I have a column with the region names, a column with how
much spending was predicted and a column with the real spend. I have
named each autoshape after the region, but am stuck now. I need the
autoshapes to show up as green if they spent within their budget or red
if not. Am pretty new to VBA, but can work with it. Many thanks for
all help.

  #2   Report Post  
Nick Hebb
 
Posts: n/a
Default

You're not going to be able to do it with conditional formatting (to
the best of my knowledge). You could do it with VBA using code such as
follows:

Const NUMREGIONS As Integer = 5

Public Sub ShadeRegions()

Dim ws As Worksheet
Dim arrRegionCosts(NUMREGIONS) As Variant
Dim arrRegionShapes(NUMREGIONS) As Shape
Dim i As Integer

Set ws = Application.Sheets("YOUR SHEET NAME")

Set arrRegionShapes(0) = ws.Shapes("AutoShape 1")
Set arrRegionShapes(1) = ws.Shapes("Autoshape 2")
Set arrRegionShapes(2) = ws.Shapes("Autoshape 3")
Set arrRegionShapes(3) = ws.Shapes("Autoshape 4")
Set arrRegionShapes(4) = ws.Shapes("Autoshape 5")

arrRegionCosts = ws.Range("A1:A5").Value
For i = 1 To NUMREGIONS
If arrRegionCosts(i, 1) 40 Then
arrRegionShapes(i - 1).Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf arrRegionCosts(i, 1) 30 Then
arrRegionShapes(i - 1).Fill.ForeColor.RGB = RGB(255, 64,
64)
ElseIf arrRegionCosts(i, 1) 20 Then
arrRegionShapes(i - 1).Fill.ForeColor.RGB = RGB(255, 128,
128)
ElseIf arrRegionCosts(i, 1) 10 Then
arrRegionShapes(i - 1).Fill.ForeColor.RGB = RGB(255, 192,
192)
Else
arrRegionShapes(i - 1).Fill.ForeColor.RGB = RGB(255, 255,
255)
End If
Next

End Sub


There are a couple of quirky points I should make about the code above.
When setting an array from a range, as follows ...
arrRegionCosts = ws.Range("A1:A5").Value

.... (1) the array created is has a base of 1 (not 0) and (2) it is 2D
by default, hence the arrRegionCosts(i, 1) subscripts.

HTH,

Nick Hebb
BreezeTree Software
http://www.breezetree.com


2.

  #3   Report Post  
 
Posts: n/a
Default

Many thanks for this. I have manipulated the code for my purposes, but
am coming up with "cant assign to array" at the following line in the
code:

arrRegionCosts = ws.Range("DB2:DB35").Value

Have not been able to get around this one.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting Error ddate Excel Worksheet Functions 0 May 5th 05 09:00 PM
difficulty with conditional formatting Deb Excel Discussion (Misc queries) 0 March 23rd 05 06:13 PM
conditional formatting question Deb Excel Discussion (Misc queries) 0 March 23rd 05 02:07 AM
Determine cells that drive conditional formatting? Nicolle K. Excel Discussion (Misc queries) 2 January 7th 05 01:08 AM
Conditional formatting not available in Excel BAB Excel Discussion (Misc queries) 2 January 1st 05 03:33 PM


All times are GMT +1. The time now is 01:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"