VBA Code to Sorting the Data



Function fnSortingData(wksRpt As Worksheet)
    
    Dim iLastrow As Integer
    
    iLastrow = wksRpt.Cells(Rows.Count, "A").End(xlUp).Row
    
    wksRpt.Sort.SortFields.Clear
    wksRpt.Sort.SortFields.Add2 Key:=Range( _
        "A2:A" & iLastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    wksRpt.Sort.SortFields.Add2 Key:=Range( _
        "G2:G" & iLastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With wksRpt.Sort
        .SetRange Range("A1:H" & iLastrow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
End Function