I have fund names in columns of one sheet("All") and weekly fund returns in the corresponding columns of other sheet("EDITED"). I defined fund names and returns as ranges and tried to sort names using returns as key in VBA. My objective is to sort every column since each column represents another week. My code is down below. Thanks in advance.
Sub Sortmydata()
Dim rng As Range
Dim keyrng As Range
For i = 5 To 385
Set rng = Worksheets("All").Range(Cells(3, i), Cells(385, i))
Set keyrng = Worksheets("EDITED").Range(Cells(3, i), Cells(385, i))
rng.Select
Selection.Sort key1:=keyrng, _
order1:=xlAscending, Header:=xlNo
i = i + 1
Next i
End Sub