I get the following error when executing my macro:
Run-time error '1004':
Sort reference is not valid. Make sure that its within the data you want to sort, and the first sort box inst the same or blank
The code fragment:
The first ".Apply" line gets selected during debugging.'Get the range sum and record it For i = 3 To 12 'REVERB1 Sum = 0 For y = iStart To iEnd Sum = Sum + Cells(y, i).Value Next y Sheet22.Cells(2, i - 1).Value = Sum Next i 'Sort Sheet22.sort.SortFields.Add Key:=Range("B2:K2"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal With Sheet22.sort .SetRange Range("B1:K2") .Header = xlYes .MatchCase = False .Orientation = xlLeftToRight .SortMethod = xlPinYin .Apply End With Sheet3.Activate For i = 3 To 12 'REVERB2 Sum = 0 For y = iStart To iEnd Sum = Sum + Cells(y, i).Value Next y Sheet22.Cells(4, i - 1).Value = Sum Next i 'Sort Sheet22.sort.SortFields.Add Key:=Range("B4:K4"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal With Sheet22.sort .SetRange Range("B3:K4") .Header = xlYes .MatchCase = False .Orientation = xlLeftToRight .SortMethod = xlPinYin .Apply End With
Any ideas on whats wrong?
Thanks in advance
Last edited by nbuk; 07-16-2010 at 12:21 PM.
Initially, while still in the writing progress (i only had one "sort") this code executed without any errors. I do not think I changed anything to it, it just started to give errors.
Please help?
Perhaps
With Sheet22.Sort .SortFields.Clear .SortFields.Add Key:=Range("B2:K2"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal .SetRange Range("B1:K2") .Header = xlYes .MatchCase = False .Orientation = xlLeftToRight .Apply End With
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Works great. Thanks!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks