PDA

View Full Version : Sorting lines in a graph's data table



jlingle
01-15-2013, 01:26 PM
In PowerPoint 2010 I am reading from a spreadsheet and populating a bar graph. Everything is working fine but I want to sort the rows. I can set the range on the graph's spreadsheet table, but when I go to sort that range I get the error "Run-time error ‘1004’: Method ‘Range” of object”_Global’ failed" on line 8 (".Sort.SortFields.Add Range("B4:B22"), xlSortOnValues, xlAscending, xlSortNormal") I can't figure out way it sets the range o.k., but then bombs when I try the sort.

'Resize and short the workbook sheet
With gWorkSheet.ListObjects("table1")
.Resize gWorkSheet.Range("A1:D" & CStr(CatNum + 1))
.Range.Select
.Sort.SortFields.Clear
End With
With gWorkSheet.ListObjects("table1")
.Sort.SortFields.Add Range("B4:B22"), xlSortOnValues, xlAscending, xlSortNormal
.Sort.SetRange Range("A4:D" & CStr(CatNum + 1))
.Sort.Header = xlGuess
.Sort.MatchCase = False
.Sort.Orientation = xlTopToBottom
.Sort.SortMethod = xlPinYin
.Sort.Apply
End With

Andy Pope
01-18-2013, 03:15 AM
Try fully qualifying the range when you use it.



.Sort.SortFields.Add gWorkSheet.Range("B4:B22"), xlSortOnValues, xlAscending, xlSortNormal

jlingle
02-08-2013, 07:04 AM
Thanks Andy. I ended up writing a short bubble sort, but this would be better. I'll give it a try when I get a moment.