none
vba Excel 2010, RGB to long color value convertor RRS feed

  • Question

  •  Hi all,

    How do I convert RGB to long color value?

    For example, RGB(255, 111, 254) is 16674815.

    Thanks ahead.

     

    Thursday, February 2, 2012 3:11 PM

Answers

  • Yes it is possible :)

    Like This?

    Sub Sample()
        Dim Col As Long
        
        '~~> RGB to LONG
        Col = RGB(255, 111, 254)
        
        Debug.Print Col
        
        '~~> LONG To RGB
        R = Col Mod 256
        G = (Col \ 256) Mod 256
        B = (Col \ 256 \ 256) Mod 256
        
        Debug.Print R
        Debug.Print G
        Debug.Print B
    End Sub
    



    Sid (A good exercise for the Heart is to bend down and help another up) Please do not email me your questions. I do not answer questions by email unless I get paid for it :) If you want, create a thread in VB.Net/Excel forum and email me the link and I will help you if I can.
    • Marked as answer by ymarkiv Thursday, February 2, 2012 4:12 PM
    Thursday, February 2, 2012 3:52 PM
    Moderator

All replies

  • I am not sure I understand your question

    Isn't this what you are trying to do?

    Sub Sample()
        Dim Col As Long
        Col = RGB(255, 111, 254)
        
        Debug.Print Col '<~~ Gives 16674815
    End Sub
    


    Sid (A good exercise for the Heart is to bend down and help another up) Please do not email me your questions. I do not answer questions by email unless I get paid for it :) If you want, create a thread in VB.Net/Excel forum and email me the link and I will help you if I can.
    Thursday, February 2, 2012 3:24 PM
    Moderator
  •  Thanks! How about converting back:

    Long -> RGB ?

    Is it possible at all?

     

    Thursday, February 2, 2012 3:33 PM
  • Yes it is possible :)

    Like This?

    Sub Sample()
        Dim Col As Long
        
        '~~> RGB to LONG
        Col = RGB(255, 111, 254)
        
        Debug.Print Col
        
        '~~> LONG To RGB
        R = Col Mod 256
        G = (Col \ 256) Mod 256
        B = (Col \ 256 \ 256) Mod 256
        
        Debug.Print R
        Debug.Print G
        Debug.Print B
    End Sub
    



    Sid (A good exercise for the Heart is to bend down and help another up) Please do not email me your questions. I do not answer questions by email unless I get paid for it :) If you want, create a thread in VB.Net/Excel forum and email me the link and I will help you if I can.
    • Marked as answer by ymarkiv Thursday, February 2, 2012 4:12 PM
    Thursday, February 2, 2012 3:52 PM
    Moderator