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