Map of USA text box font color - Andy Pope script amend

tarek

New Member
Joined
Nov 21, 2006
Messages
24
Team,

Andy Pope created a fantastic USA Interactive Map application (AJP Excel Information) which will allow users to color the states (each state resembled with an object) according to a data value in the range 0 to 9.

Based on Andy's map, I am building a dashboard to show revenues by state so I've created text boxes on top of each state object and linked the text box to cells in another sheet that hold $ value related to the particular state.

State map objects: each named in the state full name (example: California, Texas.. etc.)
State revenue text boxes: each named in the state abbreviation (example: CA, TX.. etc.)

I am attempting to amend Andy's script to give the ability to control the state revenue text box FONT color according to a data value in a range 0-9
The excel sheet (“Color_Control”) has the following defined ranges:
Name: COLOR_VALUE
Refers to: =COLOR_Control!$I$3:$I$12
Name: STATE_ABBREVIATION
Refers to: =COLOR_Control!$B$3:$C$50
Name: STATES
Refers to: =COLOR_Control!$D$3:$E$51

The map is placed in a sheet called “MainMap”


Here is the code from Andy's file"




'
' Written by Andy Pope © 2003
'
Option Explicit

Sub ColourStates()
'
' Using the values from named range STATE
' And the colours from named range STATE_COLOURS
' re colour the map on sheet MainMap
'
Dim intState As Integer
Dim strStateName As String
Dim intStateValue As Integer
Dim intColourLookup As Integer
Dim rngStates As Range
Dim rngColours As Range

Set rngStates = Range(ThisWorkbook.Names("STATES").RefersTo)
Set rngColours = Range(ThisWorkbook.Names("STATE_COLOURS").RefersTo)

With Worksheets("MainMap")
For intState = 1 To rngStates.Rows.Count
strStateName = rngStates.Cells(intState, 1).Text
intStateValue = rngStates.Cells(intState, 2).Value
If intStateValue > 9 Then
' stripped
With .Shapes(strStateName)
intColourLookup = Application.WorksheetFunction.Match(CInt(Left(CStr(intStateValue), 1)), Range("STATE_COLOURS"), True)
.Fill.Patterned msoPatternWideUpwardDiagonal
.Fill.ForeColor.RGB = rngColours.Cells(intColourLookup, 1).Offset(0, 1).Interior.Color
intColourLookup = Application.WorksheetFunction.Match(CInt(Right(CStr(intStateValue), 1)), Range("STATE_COLOURS"), True)
.Fill.BackColor.RGB = rngColours.Cells(intColourLookup, 1).Offset(0, 1).Interior.Color
End With
Else
' single colour
intColourLookup = Application.WorksheetFunction.Match(intStateValue, Range("STATE_COLOURS"), True)
With .Shapes(strStateName)
.Fill.Solid
.Fill.ForeColor.RGB = rngColours.Cells(intColourLookup, 1).Offset(0, 1).Interior.Color
End With
End If
Next
End With

End Sub



Thank you in advance for all your help
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top