Monday, January 23, 2017

Excel VBA color bar


Color scale or color bar is a color gradient color bar. The VBA code in the attached file can be used to create 3-colors color bar and 2-colors color bar. It also can generate horizontal and vertical color bars as well.

In this function you have define the following:

[1] Orientation of the color bar: horizontal "H" or vertical "V"
[2] The parent frame which will be the color bar container
[3] The element size (step) in pixels. The smaller the element size, the smoother gradient is achieved

[4] Red channel value of color 1
[5] Green channel value of color 1
[6] Blue channel value of color 1

[7] Red channel value of color 2
[8] Green channel value of color 2
[9] Blue channel value of color 2

[10] Red channel value of color 3
[11] Green channel value of color 3
[12] Blue channel value of color 3

[13] Color 2 position as a fraction of the color bar size

The color bar is simply created by creating dynamic labels with interpolated color. Each color channel is interpolated using linear interpolation.





The following are some color bars generated using the function


You can download the code from this link


Tags:

Excel, PowerPoint, Word VBA color bar

Excel VBA 2-colors bar

Excel VBA 3-colors bar

Excel VBA color gradient

Excel VBA user form color scale

Color bar interpolation

Color scale interpolation

Color gradient interpolation

Excel VBA rectangle with color gradient

Excel VBA progress bar with color gradient