Pie Graph, modify if Statement (code included)

LNG2013

Active Member
Joined
May 23, 2011
Messages
466
In my code below, I want to modify my if statement to also say if the the last values in G" & X & ":J" & X = 0 then skip that sheet as well.



Code:
Sub CreatePieChart()
Dim X, Y As Long
Dim DataArray(2, 4) As Variant
Dim WSheet As Worksheet
Dim sShtName As String
        Dim RngToCover As Range
         Dim ChtOb As ChartObject

Application.ScreenUpdating = False

For Each WSheet In Worksheets
    Sheets(WSheet.Name).Select
    sShtName = ActiveSheet.Name
 
    If Cells(1, 11).Value = "Objective" Then    'Want to add other tests here.     
        X = 2
        Y = 7
        For Z = 1 To 4
            DataArray(1, Z) = Cells(X, Y + Z - 1).Value
        Next
        X = 3
        Do While True
            If Cells(X, 1).Value = "Total" Then
                Exit Do
            End If
            X = X + 1
        Loop
        Range("G2:J2,G" & X & ":J" & X).Select
                Charts.Add
                
'~~~ The next line indicates where the chart will be placed
        ActiveChart.Location Where:=xlLocationAsObject, Name:=sShtName
        ActiveChart.ChartType = xlPie
      
'~~~ 1.) This part of the code modifies the size and positioning of the Pie Chart
      
        Set RngToCover = ActiveSheet.Range("J" & X & ":M" & X)
         Set ChtOb = ActiveChart.Parent
            ChtOb.Height = 200
            ChtOb.Width = 225
         ChtOb.Top = RngToCover.Top + 96     ' reposition
         ChtOb.Left = RngToCover.Left + 30    ' reposition
        ActiveChart.ChartArea.AutoScaleFont = False
'~~~ 2.) This part of the area modifies the area around the Pie, removing the border and shading.
    With ActiveChart.PlotArea.Border
        .Weight = xlHairline
        .LineStyle = xlNone
    End With
    With ActiveChart.PlotArea.Interior
        .ColorIndex = xlNone
    End With
 
'~~~ 3.) This section modifies the legend of the Chart
    With ActiveChart
        .Legend.LegendEntries(1).LegendKey.Interior.ColorIndex = 3
        .Legend.LegendEntries(1).LegendKey.Interior.Pattern = xlSolid
        .Legend.LegendEntries(2).LegendKey.Interior.ColorIndex = 44
        .Legend.LegendEntries(2).LegendKey.Interior.Pattern = xlSolid
        .Legend.LegendEntries(3).LegendKey.Interior.ColorIndex = 41
        .Legend.LegendEntries(3).LegendKey.Interior.Pattern = xlSolid
        .Legend.LegendEntries(4).LegendKey.Interior.ColorIndex = 4
        .Legend.LegendEntries(4).LegendKey.Interior.Pattern = xlSolid
        .Legend.Position = xlLegendPositionBottom
        .Legend.Fill.TwoColorGradient Style:=msoGradientVertical, Variant:=1
        .Legend.Fill.Visible = True
        .Legend.Fill.ForeColor.SchemeColor = 37
        .Legend.Fill.BackColor.SchemeColor = 2
        .Legend.Border.Weight = xlHairline
        .Legend.Border.LineStyle = xlNone
    End With
    With ActiveChart.Legend.Font
        .Name = "Arial Rounded MT Bold"
        .FontStyle = "Regular"
        .Size = 12
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With
    
   '~~~ This section add the title to the chart.
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Prompts"
    End With
        With ActiveChart.ChartTitle.Font
        .Name = "Arial Rounded MT Bold"
        .FontStyle = "Regular"
        .Size = 14
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With
    With ActiveChart.SeriesCollection(1)
        .Explosion = 5
    End With
   
      
        Range("M33").Select
    End If
Next
 
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,225,203
Messages
6,183,550
Members
453,168
Latest member
Luggsy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top