Goal: Apply sort to each sub-range and limit chart range to top 5 categories. Sub-ranges have been created to form charts.
I've worked on this for over a week and I'm completely stuck. Any help would be appreciated.
Sub AutoChartRejects()
Dim rngData As Range
Dim rngArea As Range
Dim TPos As Integer
Dim objChart As ChartObject
Dim xx As Series
Dim columnF As Range
Set columnF = Intersect(Range("F1").EntireColumn, ActiveSheet.UsedRange)
columnF.Value = Evaluate("IF(ROW(" & columnF.Address & "),IF(" & columnF.Address & "<>"""",TRIM(" & columnF.Address & "),""""))")
Set rngData = Range("H2", Cells(Rows.Count, 8).End(xlUp)).SpecialCells(xlCellTypeConstants)
Set xrngData = rngData.Offset(0, -2)
TPos = 0
Worksheets.Add().Name = "Charts"
For Each rngArea In rngData.Areas
' Range(xrngData, rngData).Sort _
' Key1:=.Range(.Cells(1, 3), .Cells(lastrow, lastCol)), Order1:=xlDescending, _
' MatchCase:=False, Orientation:=xlSortColumns, Header:=xlYes
TPos = TPos + 150
With objChart.Chart
Do While .SeriesCollection.Count > 0
.SeriesCollection(1).Delete
Loop
With .SeriesCollection.NewSeries
.Values = rngArea
.XValues = rngData.Offset(0, -2)
.Name = rngArea.Cells(1, 1).Offset(-1, -7) 'name for legend, needs to be name for Chart Title
.ChartType = xlColumnStacked
End With
objChart.Activate
.HasTitle = True
.ChartTitle.Characters.Text = "Reject Code by Machine"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Defect Type"
.ChartTitle.Font.Size = 9
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "# Rejects"
With .PlotArea
.Top = 10
.Left = 10
.Width = 152
.Height = 122
End With
End With
Next
End Sub
I've worked on this for over a week and I'm completely stuck. Any help would be appreciated.
Sub AutoChartRejects()
Dim rngData As Range
Dim rngArea As Range
Dim TPos As Integer
Dim objChart As ChartObject
Dim xx As Series
Dim columnF As Range
Set columnF = Intersect(Range("F1").EntireColumn, ActiveSheet.UsedRange)
columnF.Value = Evaluate("IF(ROW(" & columnF.Address & "),IF(" & columnF.Address & "<>"""",TRIM(" & columnF.Address & "),""""))")
Set rngData = Range("H2", Cells(Rows.Count, 8).End(xlUp)).SpecialCells(xlCellTypeConstants)
Set xrngData = rngData.Offset(0, -2)
TPos = 0
Worksheets.Add().Name = "Charts"
For Each rngArea In rngData.Areas
' Range(xrngData, rngData).Sort _
' Key1:=.Range(.Cells(1, 3), .Cells(lastrow, lastCol)), Order1:=xlDescending, _
' MatchCase:=False, Orientation:=xlSortColumns, Header:=xlYes
TPos = TPos + 150
With objChart.Chart
Do While .SeriesCollection.Count > 0
.SeriesCollection(1).Delete
Loop
With .SeriesCollection.NewSeries
.Values = rngArea
.XValues = rngData.Offset(0, -2)
.Name = rngArea.Cells(1, 1).Offset(-1, -7) 'name for legend, needs to be name for Chart Title
.ChartType = xlColumnStacked
End With
objChart.Activate
.HasTitle = True
.ChartTitle.Characters.Text = "Reject Code by Machine"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Defect Type"
.ChartTitle.Font.Size = 9
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "# Rejects"
With .PlotArea
.Top = 10
.Left = 10
.Width = 152
.Height = 122
End With
End With
Next
End Sub