+ Reply to Thread
Results 1 to 5 of 5

Change Interior Color using Cell Value

Hybrid View

  1. #1
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Change Interior Color using Cell Value

    I am trying to adjust a cell's color using RGB. I know how to force the color using the RGB in vba but is there a way to do it based on a cells value?


    This is the code i am trying to write:

    Sub test2()
    Range("B3").Interior.Color = RGB((Range("C3").Value))
    End Sub
    The value of Range("C3") = "(112, 133, 119)" (without the quotes)
    Last edited by PY_; 03-23-2011 at 01:08 PM.

  2. #2
    Valued Forum Contributor Sadath31's Avatar
    Join Date
    03-02-2011
    Location
    Dammam, Saudi Arabia
    MS-Off Ver
    Office 365
    Posts
    452

    Re: Change Interior Color using Cell Value

    may be this
    Sub test2()
    R = Mid(Range("B3"), 2, 3) * 1
    G = Mid(Range("B3"), 6, 3) * 1
    B = Mid(Range("B3"), 10, 3) * 1
    Range("B3").Interior.Color = RGB(R, G, B)
    End Sub

  3. #3
    Registered User
    Join Date
    03-04-2011
    Location
    Gananoque, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Change Interior Color using Cell Value

    Quote Originally Posted by PY_ View Post
    I am trying to adjust a cell's color using RGB. I know how to force the color using the RGB in vba but is there a way to do it based on a cells value?


    This is the code i am trying to write:

    Sub test2()
    Range("B3").Interior.Color = RGB((Range("C3").Value))
    End Sub
    The value of Range("C3") = "(112, 133, 119)" (without the quotes)

    I believe the most simplest and easiest way that i have ever came across was conditional formatting.

    Now Conditional Formatting may not be exactly what your looking for however you can make it format the cells however you want. And it saves you time in the long run.
    Robert B | TB Consultants

  4. #4
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: Change Interior Color using Cell Value

    The "Mid(Range" code will not really work because this will be performed on multiple lines and i was trying to keep it simple.

    Your correct, conditional formatting will not work for what i am trying to do. I guess ill look into how to add Vlookup to vba because the value in C3 is just a combination of (3) vlookups. I was hoping it would be easier this way instead but it doesnt seem so.

  5. #5
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: Change Interior Color using Cell Value

    I was able to work around that another way. I was trying not to have data in 2 more columns but its the easiest way. I just did a worksheet change and have the following in it:
    Range("B3").Interior.Color = RGB(Range("C3").Value, Range("D3").Value, Range("E3").Value)

+ 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