View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Multiple Sort Ranges via VBA Q

Hi Sean,

Am Wed, 16 Nov 2016 06:05:01 -0800 (PST) schrieb :

Code below sorts 2 Range Names called "Sort1" & "Sort2". It uses Column I as the Sort field from Largest down

I have over 50 of these Ranges, is there anyway to short circuit the code below to include all 50 of these Sort Ranges?


if the ranges have always 7 rows you could do it with a loop:

Sub SpecialSort()
Dim i As Long, LRow As Long

With Sheets("Input")
LRow = .Cells(.Rows.Count, "I").End(xlUp).Row
For i = 15 To LRow Step 8
.Range("F" & i & ":I" & i + 7).Sort Key1:=Range("I" & i), _
order1:=xlDescending, Header:=xlNo
Next
End With
End Sub

Else you could write all ranges in an array and then step through this
array.


Regards
Claus B.
--
Windows10
Office 2016