Sort within an Array used for Charts

tmart

New Member
Joined
Oct 6, 2011
Messages
3
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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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