Would you help me understand this snippset:
First, it seems that a sorting rule is added with
MainSheet.Sort.SortFields.Clear For lI = 1 To vSortKeys(0, 1) MainSheet.Sort.SortFields.Add Key:=Range(vSortKeys(lI, 1) & 2), SortOn:=xlSortOnValues, Order:=vSortKeys(lI, 2), DataOption:=xlSortNormal Next
Then, I understand that the following code is effectively running the sort
With MainSheet.Sort .SetRange Range("A" & lFrom & ":" & GEN_REV_END & lTo) .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With
Is this interpretation correct - need to add a sorting rule first, then apply it with the second part ?
Then, why are we defining a range for sort in the second part, in
With MainSheet.Sort .SetRange Range("A" & lFrom & ":" & GEN_REV_END & lTo) End With
Is it not already in the rule that we sort for Key:=Range(vSortKeys(lI, 1) & 2)
? On which range of cells is the sort effectively run ?