I get error 1004: Method Range of Object Global Failed or other associated messages when I try to use an array of column numbers as variables in sorting or otherwise selecting a range. I sort on two criteria, the first is a constant column. The total number of rows of data is held in the variable SnapShot. Here's my code...help?
'create arrays to iterate through sorting columns ascending or descending
Dim AscArray As Variant
AscArray = Array(7, 8, 12, 13, 18, 19, 22)
Dim DescArray As Variant
DescArray = Array(6, 9, 10, 11, 14, 15, 16, 17, 20, 21, 23, 24)
Dim ColumnNumber As Variant
'iterate through Ascending array
For Each ColumnNumber In AscArray
'sort by column
ActiveWorkbook.Worksheets("Rankings").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Rankings").Sort.SortFields.Add Key:=Range("A2:A" & SnapShot _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Rankings").Sort.SortFields.Add Key:=Range(Cells(ColumnNumber, 2), Cells(ColumnNumber, SnapShot) _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Rankings").Sort
.SetRange Range("A1:AC" & SnapShot)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'highlight best value and worst value green and red
Range(Cells(ColumnNumber, 2)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range(Cells(ColumnNumber, SnapShot)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Next
Bookmarks