VBA for Excel 2007 tutorial-chart area pattern style

Chart area pattern style

In this VBA code example, you will learn to set the pattern style of chart area. To apply a pattern style to a chart area, you can use the Patterned() method. This method has the following prototype:


The Pattern_Type argument that represents the type of pattern to be applied to the chart area can take the following values: msoPattern5Percent, msoPattern10Percent, msoPatternCross, msoPatternDivot, msoPatternDottedDiamon, msoPatternDashedVertical, msoPatternHorizental msoPatternDarkVertical,etc.

VBA for Excel: VBA example code to set chart area pattern

To run this VBA example code, you can copy and paste the VBA code below in to the block of Worksheet_Activate() procedure. To open this block, double-click the current worksheet, then in the objects dropdown list select Sheet1 and in events list select Activate.

VBA code for this example:

Option Explicit
Private Sub Worksheet_Activate()
    Dim i As Integer
    'Fill Source data
    For i = 1 To 10
         Range("A" & i) = Int(100 * Rnd) + 1
         Range("B" & i) = Int(100 * Rnd) + 1
    'Select the data source
    'Create a clusted column chart
    ActiveSheet.Shapes.AddChart xl3DColumn, 10, 180
    ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$B$10"), PlotBy:=xlColumns
    'Fill the chart area with a pattern style
ActiveChart.ChartArea.Format.Fill.Patterned msoPattern10Percent

End Sub


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.