I have a number of different columns i want to sort on the same worksheet but i want to sort each collumn by a different range.
currently im using this code
g1summary.Range("R5:U10").Sort Key1:=g1summary.Range("U5"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
But i want it so i can use a varible range so i can put the code within a loop
ive tried this but it doesnt work...
g1summary.Range(Cells(5, n), Cells(norows, n+3)).Sort Key1:=g1summary.Range(cells(5, n+3), cells(norows, n+3), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
n is the variable representing the column number
a larger overview of my code is..
Do Until shopcount > 8
i = 14
Do Until i > 31
module = sc1.Cells(i, "C")
acthours = sc1.Cells(i, shopcount)
stdhours = sc1.Cells(i, shopcount + 1)
shop = sc1.Cells(12, shopcount)
'do while std hours is blank
Do While stdhours = "" And i < 32
i = i + 1
If i = 32 Then
Else
module = sc1.Cells(i, "C")
acthours = sc1.Cells(i, shopcount)
stdhours = sc1.Cells(i, shopcount + 1)
shop = sc1.Cells(12, shopcount)
End If
Loop
'print loop
n = 18
exitloop = False
Do Until n > 83 Or exitloop = True
module2 = g1summary.Cells(3, n)
shop2 = g1summary.Cells(2, n)
norows = g1summary.Cells(1, n + 1) + 2
If module = module2 And shop = shop2 And stdhours <> "" Then
g1summary.Cells(norows, n) = ESN
g1summary.Cells(norows, n + 1) = acthours
g1summary.Cells(norows, n + 2) = stdhours
g1summary.Cells(norows, n + 3) = Date
exitloop = True
'sort summary data
'!!!!!!!!!!!!!!!!!!!!!!!!
'code in question
'instead of using this code is there a way of using a variable range?
g1summary.Range("R5:U10").Sort Key1:=g1summary.Range("U5"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End If
'next shop on g1 summary
n = n + 4
'jump gap
If n = 78 Then
n = 79
End If
Loop
'End of print loop
i = i + 1
Loop
'next shop on sc3
shopcount = shopcount + 3
Loop
Thanks for any help
Bookmarks