Share

Excel VBA, Create Gradient

This article provides code snippets for creating gradients. Note the codes in this article merely create the default gradient. In order to modify the gradients please see the topics covered in the article Excel VBA, Fill Effects, Gradient

Jump To:


Cell:

The code below creates a gradient for cell A1:

Range("A1").Interior.Pattern = xlPatternLinearGradient

Result:

Excel VBA, Create Gradient
Note: The gradient created is the default gradient. You can later modify it using the topics covered in the article Excel VBA, Fill Effects, Gradient.


Range:

The following code creates a gradient for the range "A1:C3":

Range("A1:C3").Interior.Pattern = xlPatternLinearGradient

The code below is also equivalent to the code above:

Range(cells(1, 1), cells(3, 3)).Interior.Pattern = _
xlPatternLinearGradient

Result:

Excel VBA, Create Gradient Range
Note: The gradient created is the default gradient. You can later modify it using the topics covered in the article Excel VBA, Fill Effects, Gradient.


Column:

The following code creates a gradient for column 2:

Columns(2).Interior.Pattern = xlPatternRectangularGradient

Before:

Excel VBA, Create, Gradient
After:

Excel VBA, Create, Gradient Column After
Note: The gradient created is the default gradient. You can later modify it using the topics covered in the article Excel VBA, Fill Effects, Gradient.


Row:

The following code creates a gradient for row 3:

Rows(3).Interior.Pattern = xlPatternRectangularGradient

Before:

Excel VBA, Create, Gradient Row

After:

Excel VBA, Create, Gradient Row After

Note: The gradient created is the default gradient. You can later modify it using the topics covered in the article Excel VBA, Fill Effects, Gradient.


Sheet:

The following code creates a gradient for sheet 2:

Sheet2.Cells.Interior.Pattern = xlPatternRectangularGradient

Before:

Excel VBA, Create, Gradient Row

After:

Excel VBA, Create, Gradient Sheet

Note: The gradient created is the default gradient. You can later modify it using the topics covered in the article Excel VBA, Fill Effects, 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 *