Excel VBA, Column Gradient Color

In the article Excel VBA, Gradient’s Colors I’ve explained the basics about working with gradient’s color. I’m assuming the reader is familiar with the topics covered in that article.


Gradient Color, Column:

In the article Excel VBA, Gradient’s Colors I provided 2 examples for creating gradients with different colors. The examples created a gradient with multiple colors for cell A1. In this example I will apply the gradient used in example 2 in that article to column 2:

Sub Example2()
Dim objColorStop As ColorStop

Columns(2).Interior.Pattern = xlPatternLinearGradient
'changes its orientation
Columns(2).Interior.Gradient.Degree = 90
'clears the previous colostop objects
Columns(2).Interior.Gradient.ColorStops.Clear

Set objColorStop = Columns(2).Interior.Gradient.ColorStops.Add(0)
objColorStop.Color = vbYellow

Set objColorStop = Columns(2).Interior.Gradient.ColorStops.Add(0.33)
objColorStop.Color = vbRed

Set objColorStop = Columns(2).Interior.Gradient.ColorStops.Add(0.66)
objColorStop.Color = vbGreen

Set objColorStop = Columns(2).Interior.Gradient.ColorStops.Add(1)
objColorStop.Color = vbBlue
End Sub

Result:

Excel VBA, Gradient Color Column

 

Note: Intellisense may cease to display after .gradient.

 

See also:

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

 

Leave a Reply

Your email address will not be published. Required fields are marked *