+ Reply to Thread
Results 1 to 4 of 4

Macro that automatically sorts by date without pressing a shortcut

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Phoenix
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro that automatically sorts by date without pressing a shortcut

    Hi everyone - I'm sure this has been asked before, but I had a hard time finding it in the forum.

    So I'm working on a table with a date column, issue column, effects column, comments column, and training provided column.

    My co-worker wants to be able to add a new record including a date, and have that entire row automatically jump into an organized by date, chronological position.

    Sometimes the new entries will be current dates, other times they might be older dates (in which case they might have to jump up in the list quite a bit).

    The farthest I've gotten with the VBA macro is creating one with a shortcut key and relative pathways, but neither of those things work because my co-worker wants it to happen automatically when the record is entered, and relative pathways don't work because the sort doesn't end up applying to the whole table. (It's just all I could get working.)

    Does anyone have any ideas? Here's the Macro I had:

    Sub Macro2()
    '
    ' Macro2 Macro
    '
    ' Keyboard Shortcut: Ctrl+u
    '
    ActiveCell.Offset(-11, 0).Range("A1:A500").Select
    ActiveWindow.SmallScroll Down:=-30
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=ActiveCell, _
    SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("Sheet1").Sort
    .SetRange ActiveCell.Range("A1:E12")
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    ActiveCell.Offset(1, 0).Range("A1").Select
    End Sub

    Here's basically what the table looks like and I've attached it as well:

    ExcelCapture.JPG

    Test.xlsm

  2. #2
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that automatically sorts by date without pressing a shortcut

    Hi Fella,

    For this purpose you should use worksheet's change event as it gets invoked whenever the changes are made to the cell values. Following is the implementation.

    Code to Sort : Based on your example:
    Please Login or Register  to view this content.
    and code for change event
    Please Login or Register  to view this content.
    Attached Files Attached Files
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  3. #3
    Registered User
    Join Date
    08-21-2013
    Location
    Phoenix
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro that automatically sorts by date without pressing a shortcut

    Awesome! Thank you so so much!! This is working perfectly!

  4. #4
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Macro that automatically sorts by date without pressing a shortcut

    Glad to help!

+ 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] Line plot which automatically sorts values from lowest to highest
    By excelactuary in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-19-2013, 05:27 AM
  2. [SOLVED] Macro w shortcut key to paste date 28 days from today into active cell
    By Zooka in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-07-2013, 06:08 PM
  3. Linking Cells so sorts of one columb sorts another
    By excellerator22 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-12-2008, 11:26 PM
  4. Need a spreadsheet that sorts by month/yr & 2 other sorts w/total
    By Spreadsheet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2006, 09:45 AM
  5. Replies: 2
    Last Post: 01-01-2006, 02:10 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