+ Reply to Thread
Results 1 to 6 of 6

sorting a selected range by date, oldest to newest

Hybrid View

  1. #1
    Registered User
    Join Date
    07-06-2012
    Location
    Edmonton
    MS-Off Ver
    Excel 2003
    Posts
    15

    sorting a selected range by date, oldest to newest

    Hey guys, simple question for all you VBA geniuses. I need code that will sort a range of data which I have selected, from oldest to newest. The dates are in the second column (B). If possible, it would be fantastic if the code would also subtotal column H in the selection.

    Thanks in advance, yolo!

  2. #2
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: sorting a selected range by date, oldest to newest

    Just record a macro of you selecting the data, sorting it, and adding subtotal of column H. Then hit stop recording and it will spit out the code of your exact commands under a vba module (hit alt + F11 to find your code under a newly generate module).

  3. #3
    Registered User
    Join Date
    07-06-2012
    Location
    Edmonton
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: sorting a selected range by date, oldest to newest

    i tried doing that. it seems as though the macro only performs the operation on the range that i selected (for example A1:F6), rather than any range that I choose to select afterward

  4. #4
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: sorting a selected range by date, oldest to newest

    post your recorded code and I'll tweak it around.

  5. #5
    Registered User
    Join Date
    07-06-2012
    Location
    Edmonton
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: sorting a selected range by date, oldest to newest

    Sub subtt()
    '
    ' subtt Macro
    '

    '
    Range("I14").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-12]C:R[-1]C)"
    Range("I14").Select
    Selection.AutoFill Destination:=Range("I14:T14"), Type:=xlFillDefault
    Range("I14:T14").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    End Sub

  6. #6
    Registered User
    Join Date
    07-06-2012
    Location
    Edmonton
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: sorting a selected range by date, oldest to newest

    sorry for the lag in my response, its been busy over here! columns I through T are all values that need to be subtotaled. however, the rows and range for the selection will change as i move down the worksheet. thanks for all your help! yolo!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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