+ Reply to Thread
Results 1 to 2 of 2

Part of function isnt working

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    35

    Part of function isnt working

    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)

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,636

    Re: Part of function isnt working

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1