+ Reply to Thread
Results 1 to 2 of 2

Sorting all data based on data in single column (DATES)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Sorting all data based on data in single column (DATES)

    Have this excel sheet and I need to sort all columns based of on data in Column H
    • Column H are dates
    • Ask the user to select the range
    • Once selected, sort all data based on the values in column H in newest to oldest

    I tried the following :


    Sub qwerty()
    
    
    
        Dim r As Range
        Dim v As String
        Dim x As String
        
        
    
     Set r = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
     r.Select
     
    
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=r _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
           
             Dim rr As Range
            rr = Range("I2").End(xlDown)
    '           ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("I2:I100") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet1").Sort
      
            
            
            
            
            .SetRange Range("A2:I2.End(xlDown)")
            
            
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
    End Sub

    Problem I encountered:
    • Unable to select all the rows and columns – I think I am unable to tell it which is the LAST ROW that needs to be selected


    Another thing I tried doing is:
    • Record the macro and go to DATA>Sort and select the columns and sort them from newest to oldest.



    This gives the output but :
    • It sorts row 1 too
    • The selection has to be a user input using input box

    FILE ATTACHED:

    Thanks,





    xlmxm.xlsm
    Last edited by subbby; 10-15-2013 at 04:11 PM.

  2. #2
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Re: Sorting all data based on data in single column (DATES)

    Tried this code. still not working

    Sub Macro7()
    
        Dim rng As Range
        Set rng = Range(Range("L2"), Range("L3").End(xlDown))
        
       rng.Select
       
        
    
            
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
       
                      ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range(Range("L3"), Range("L3").End(xlDown)) _
                , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    
    Dim LR  As Long
    Dim rLastCell As Range
    
    
                
        With ActiveWorkbook.Worksheets("Sheet1").Sort
    '        .SetRange Range("A2:L100")
    Set rLastCell = .Cells.Find("*", .Cells(12, 2), xlValues, xlPart, , xlPrevious)
          .SetRange (.Range("L2").rLastCell)
          
            .Header = xlYes
            .MatchCase = False
    '        .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
    End Sub
    Would be glad if someone could assist me .

    I am unable to set the range inside the "WITH" .. "END WITH" option used in my code

+ 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] Sorting Data to New Worksheet Based off of Entry in Column A
    By dirtdoctor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-30-2013, 12:03 PM
  2. [SOLVED] Sorting data into multiple columns based on a single column
    By J.McQ in forum Excel General
    Replies: 7
    Last Post: 03-16-2013, 11:26 AM
  3. [SOLVED] Sorting rows of data based off a single column for a variable number of entries.
    By soxcrates in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2012, 12:31 PM
  4. Sorting Rows Based on a Column Data
    By amtrane in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-21-2007, 05:47 PM
  5. Replies: 1
    Last Post: 07-25-2006, 05:29 AM

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