Search code examples
vbacolorstransparencycell

VBA: Set transparency level in cell


I have a pie chart and I would like to put a legend with the same colors in the cells. The Pie chart has a transparency of 22.5%.

If I use the same RGB combination when I set the color in the cell, this color is different because it is much darker.

'___COLORS FOR LEGEND PIE____
If inc < 14 Then ws.Cells(rx + inc, 19).Interior.Color = RGB(colorR, colorG, colorB)

Is there a way to set transparency? I know it is possible in the charts.

If there is no way to set transparency, how canm I change my RGB code to adapt to a transparency of 22.5%?


Solution

  • The answer is you can't set the transparency of a cell in Excel.

    This is because the Range.Interior.Color only supports the RGB and not RGBA. A - stands for ALPHA which is used for transparency.

    One way around it (which I wouldn't recommend) would be to insert a shape (say a rectangle) over the cell and set its transparency to match the already transparent chart but if you have a lot of data this will definitely slow things down and if your data chages often or you are inserting/removing rows this will just be a real pain in the back bone.

    Another idea would be to go online and find 2 sets of colors RGBA and its somehow matching RGB equivalents. I have seen such solutions before but never tried it myself so I can't give you any tips on it.