I'm using Excel 2003 to produce a UK map showing areas pinpointed with textboxes that are coloured Red/Amber/Green.
In my worksheet there are 100+ Text Boxes on an overlay of a UK map labeled "1" to "150"; they are also named "Text Box 001" to "Text Box 150" respectively.
Column P, rows 1 to 150 show numbers obtained via a vlookup formula based on text in the adjacent column.
I'm trying to automatically change each textbox based on the number in Column P.
i.e. 2.5 or less should colour the textbox red
Greater than 2.5 and less than 2.75 should colour the textbox yellow
Greater than 2.75 should colour the the text box green
Anything else should colour the textbox white
so if it worked:
P19 is 4 so 'Text Box 019' should be green
P101 is 1.1 so 'Text Box 101' should be red
P140 is empty so 'Text Box 140' should be coloured white, etc.
I found a semi-relevant post on the forum and used this code:
Problem 1: The code doesn't seem to register the value of the vlookup result - I just get red text boxes. If I type over the vlookup result with the same value it then starts working.
Problem 2: Is there an easy way to change yellow to Amber? vbAmber results in a black box.
Problem 3: I'm guessing repeating that bit of code 150 times to colour each respective textbox is bad coding. Given that the textbox names are cosistant, is there a workaround to make it more concise?
Thanks in advance!
In my worksheet there are 100+ Text Boxes on an overlay of a UK map labeled "1" to "150"; they are also named "Text Box 001" to "Text Box 150" respectively.
Column P, rows 1 to 150 show numbers obtained via a vlookup formula based on text in the adjacent column.
I'm trying to automatically change each textbox based on the number in Column P.
i.e. 2.5 or less should colour the textbox red
Greater than 2.5 and less than 2.75 should colour the textbox yellow
Greater than 2.75 should colour the the text box green
Anything else should colour the textbox white
so if it worked:
P19 is 4 so 'Text Box 019' should be green
P101 is 1.1 so 'Text Box 101' should be red
P140 is empty so 'Text Box 140' should be coloured white, etc.
I found a semi-relevant post on the forum and used this code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("P1")) Is Nothing Then
ActiveSheet.Shapes("Text Box 001").Fill.ForeColor.RGB = vbWhite
If IsNumeric(Target.Value) Then
If Target.Value <= 2.5 Then
ActiveSheet.Shapes("Text Box 001").Fill.ForeColor.RGB = vbRed
ElseIf Target.Value > 2.5 And Target.Value < 2.75 Then
ActiveSheet.Shapes("Text Box 001").Fill.ForeColor.RGB = vbYellow
Else
ActiveSheet.Shapes("Text Box 001").Fill.ForeColor.RGB = vbGreen
End If
End If
End If
End Sub
Problem 1: The code doesn't seem to register the value of the vlookup result - I just get red text boxes. If I type over the vlookup result with the same value it then starts working.
Problem 2: Is there an easy way to change yellow to Amber? vbAmber results in a black box.
Problem 3: I'm guessing repeating that bit of code 150 times to colour each respective textbox is bad coding. Given that the textbox names are cosistant, is there a workaround to make it more concise?
Thanks in advance!