+ Reply to Thread
Results 1 to 3 of 3

Macro for sorting Z to A

  1. #1
    Registered User
    Join Date
    12-12-2015
    Location
    United States
    MS-Off Ver
    2013
    Posts
    18

    Macro for sorting Z to A

    Hello all, requesting help with sorting...the macro I have is recorded, but the recorder sets a specific range...the data doesnt always fall in this range, sometimes its longer/shorter....does anyone know how to sort data regardless of where the last line of data is? here is the code I have (the bolded part is what im talking about)


    Sub CC2()
    '
    Columns("A:A").RemoveDuplicates Columns:=1, Header:=xlYes

    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],DLL!C[-1],1,FALSE)"
    ActiveCell.Offset(0, -1).Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(0, 1).Select
    Range(Selection, Selection.End(xlUp)).Select
    Selection.FillDown

    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range( _
    "B2:B1474"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal

    With ActiveWorkbook.Worksheets("Sheet1").Sort
    .SetRange Range("A1:F1474")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With

    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Macro for sorting Z to A

    Code Tags
    You can edit you original post and add the code tags.

    -
    AA CodeTags.jpg

  3. #3
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Macro for sorting Z to A

    Change ranges.

    "B2:B1474" to "B:B"
    "A1:F1474" to "A:F"

    should help.

    (not tested).
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro for sorting
    By fantasylo in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-17-2018, 04:00 AM
  2. [SOLVED] Sorting Macro and Inserting Row Macro help
    By juskojj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2012, 08:24 AM
  3. Sorting after using a macro
    By kamcam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2012, 04:48 PM
  4. [SOLVED] sorting macro
    By mike02 in forum Excel General
    Replies: 4
    Last Post: 08-02-2012, 04:59 PM
  5. Sorting using macro
    By jawad rasool in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2012, 12:47 AM
  6. [SOLVED] Macro Sorting Help
    By JR in forum Excel General
    Replies: 0
    Last Post: 06-09-2005, 01:05 PM

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