+ Reply to Thread
Results 1 to 3 of 3

Dynamic Sorting Problem

  1. #1
    Registered User
    Join Date
    04-15-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2007
    Posts
    36

    Question Dynamic Sorting Problem

    Sub Order()

    LRow = Range("D" & Rows.Count).End(xlUp).Row
    Range("A2").Select
    ActiveWorkbook.Worksheets("WS1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("WS1").Sort.SortFields.Add Key:=Range("L2:L" & LRow _
    ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("WS1").Sort.SortFields.Add Key:=Range("I2:I" & LRow _
    ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortTextAsNumbers
    ActiveWorkbook.Worksheets("WS1").Sort.SortFields.Add Key:=Range("P2:P" & LRow _
    ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("WS").Sort
    .SetRange Range("A1:A" & LRow)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply End With
    End Sub
    Hello! I have a problem with this thing I tried. I am pretty much a beginner, so I tried to steal ideas from watching how a macro works. Then I tried to make it dynamic, because the list i am using it for is changing every time.

    But when I tried to apply this version, it just says that has a problem by executing @ .Apply (marked BOLD)

    I know this looks horrible. How should I do it?

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Dynamic Sorting Problem

    I did not try it but here what I saw:
    Please Login or Register  to view this content.
    Hope this helps
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    04-15-2013
    Location
    Hungary
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Dynamic Sorting Problem

    Yeah, thanks, finally got some time to check it. All I was missing was the Range at the end. You helped a lot! Thanks mate!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1