Excel VBA, Sheet 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, Row:

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 of that article to an entire sheet:

Sub Example2()
Dim objColorStop As ColorStop

Sheet6.Cells.Interior.Pattern = xlPatternLinearGradient
'changes its orientation
Sheet6.Cells.Interior.Gradient.Degree = 90
'clears the previous colostop objects
Sheet6.Cells.Interior.Gradient.ColorStops.Clear

Set objColorStop = Sheet6.Cells.Interior.Gradient.ColorStops.Add(0)
objColorStop.Color = vbYellow

Set objColorStop = Sheet6.Cells.Interior.Gradient.ColorStops.Add(0.33)
objColorStop.Color = vbRed

Set objColorStop = Sheet6.Cells.Interior.Gradient.ColorStops.Add(0.66)
objColorStop.Color = vbGreen

Set objColorStop = Sheet6.Cells.Interior.Gradient.ColorStops.Add(1)
objColorStop.Color = vbBlue
End Sub

Result:

Excel, VBA, Gradient, Sheet

 

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 *