CatParky
CatParky

Reputation: 189

Excel VBA Hex colours not showing correctly

Please can someone help me before I go a little crazy !

I'm trying to use a scale of colours in VBA and I have the RGB and the Hex values however not all of them output the way I would expect and I think it's to do with the &H prefix

For example

I have a lovely shade of red (RGB 248:105:107 HEX F8696B) that when I'm writing my code I input as :

Const Band10Colour As Long = &HF8696B

However this is a lovely purple colour

When I look up the the RGB of the purple colour it's the reverse of the one I wanted 107:105:248 !!

How can I get the correct &H hex value so that VBA will understand I want a red colour not purple !!

Upvotes: 0

Views: 709

Answers (1)

Bathsheba
Bathsheba

Reputation: 234635

You ought to use VBA.RGB(...) instead. The problem you're experiencing is down to the memory layout of Long clashing unexpectedly with the way the RGB structure is defined internally.

As VBA.RGB(...) returns a Long, just store the function output.

Upvotes: 3

Related Questions