+ Reply to Thread
Results 1 to 4 of 4

SORT with changing value in column

  1. #1
    Forum Contributor
    Join Date
    05-04-2015
    Location
    Atlanta GA
    MS-Off Ver
    2010
    Posts
    106

    SORT with changing value in column

    I would like to SORT a trio of columns with the column to sort by being C.
    The value in the range would be determined by a changing value in cell E3.
    B3 & C3 would be static while C# & D# would change.

    The three statements in RED are what I need help with

    'cell e3 contains value for columns C & D

    Range("B3:D22").Select
    ActiveWorkbook.Worksheets("Players").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Players").Sort.SortFields.Add2 Key:=Range("C3:C22" _
    ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Players").Sort
    .SetRange Range("B2:D22")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,022

    Re: SORT with changing value in column

    As long as "Players" is the activesheet

    Range("B3:D22").Select ' Entire line can be deleted

    Range("C3:C22" _
    )

    Can be just

    Range("C3")

    and

    Range("B2:D22")

    could become this, as long as headers are in row 2, and nothing else is below the last value of column D:

    Range("B2:D" & Cells(Rows.Count,"D").End(xlUp).Row)

    Or, maybe, if the headers are in row 1:

    Range("B:D")
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    05-04-2015
    Location
    Atlanta GA
    MS-Off Ver
    2010
    Posts
    106

    Re: SORT with changing value in column

    Actually, this is what worked for me:

    Range("B3:D" & Cells(3, 5)).Select
    ActiveWorkbook.Worksheets("Players").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Players").Sort.SortFields.Add2 Key:=Range("C3:C" & Cells(3, 5) _
    ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Players").Sort
    .SetRange Range("B2:D" & Cells(3, 5))
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With

    Thanks for your help

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,022

    Re: SORT with changing value in column

    So you have a formula or other entry in cell E3 that returns the last row of column D.....

+ 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. Replies: 8
    Last Post: 05-12-2019, 07:35 AM
  2. Replies: 12
    Last Post: 09-08-2018, 10:34 PM
  3. Replies: 1
    Last Post: 03-29-2018, 07:58 AM
  4. How to sort and keep a column from changing?
    By Chansforpapalote in forum Excel General
    Replies: 1
    Last Post: 06-04-2014, 03:50 PM
  5. Replies: 2
    Last Post: 01-15-2014, 09:31 AM
  6. Replies: 4
    Last Post: 11-20-2012, 06:00 PM
  7. [SOLVED] Macro Sort column(s) with range that is continuously changing or being added to
    By russell.suereth in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-14-2012, 12:01 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