Color in Visual Basic

Discussion in 'Excel' started by tcebob, Mar 9, 2017.

  1. tcebob

    tcebob

    Joined:
    Jun 11, 2011
    Messages:
    14
    Likes Received:
    2
    Here's an excerpt from a macro I recorded to try to dope out the color code:
    .Color = 7260360
    This is R=200,G=200,B=110
    or Hex c8c86e
    How can I translate from RGB or Hex to VB? (or back)
     
    tcebob, Mar 9, 2017
    #1
    1. Advertisements

  2. tcebob

    Steve from Texas

    Joined:
    Mar 9, 2017
    Messages:
    5
    Likes Received:
    3
    The RGB color code is [blue]*256*256 + [green]*256 + [red]
    So, for yours 110*256*256 + 200*256 + 200 = 7260360
     
    Steve from Texas, Mar 10, 2017
    #2
    Becky likes this.
    1. Advertisements

  3. tcebob

    Luck

    Joined:
    Dec 28, 2017
    Messages:
    8
    Likes Received:
    0
    Try this
    Sub Test()
    Dim LR as long
    LR= Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To LR
    R = Cells(i, 1).Value
    G = Cells(i, 2).Value
    B = Cells(i, 3).Value
    Cells(i, 4).Interior.Color =RGB(R,G,B)
    Next i
    End Sub
     
    Luck, Dec 28, 2017
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
Loading...