1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

VBA Help required, issues with sorting.

Discussion in 'Visual Basic ( VB )' started by Naigan, Dec 8, 2008.

  1. Naigan

    Naigan New Member

    Joined:
    Nov 29, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys, i'm having a problem here, i'm trying to create a macro to sort a range of data, I can get it to select the whole table easily, but the problem is after I create the macro, if I wanted to add further data to it, it misses out that data when doing the sorting process.. If anyone has any recommendations i'd appreciate it, here's the code...

    Code:
    Range("A1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlToRight)).Select
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("M2:M18") _
            , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet1").Sort
            .SetRange Range("A1:M18")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
     

Share This Page