Hi guys,
I have the following function. The first part works fine (when ColorByRoom = True) but i keep getting #VALUE! errors for the false bit.
when i remove the "Worksheets("SnapShot").Shapes(ShapeName).Fill.ForeColor.RGB = RGB(192, 192, 192)" line then the code works fine. however, i want to keep this code because if ColorByRoom = False then i want to colour the shape grey.
here is all the code
Function ColorByRoom(ShapeName As String, Pop As Double) As Boolean
'Fill a shape named ShapeName with color green according to the population.
'Largest population (Russia) -> dark green (140,041,247)
'Smallest population (Luxembourg) -> very light green (491,775)
Dim Pfac As Single 'area factor
Dim RB As Integer 'red & blue color values
Dim G As Integer 'green color value
On Error GoTo NotFound
Pfac = Sqr(Pop / 104776#)
RB = (1 - Pfac) * 255
G = 255 - Pfac * 130
With Worksheets("SnapShot").Shapes(ShapeName)
.Fill.ForeColor.RGB = RGB(RB, G, RB)
End With
ColorByRoom = True
Exit Function
NotFound:
ColorByRoom = False
Worksheets("SnapShot").Shapes(ShapeName).Fill.ForeColor.RGB = RGB(192, 192, 192)
Bookmarks