+ Reply to Thread
Results 1 to 4 of 4

Autosort all data by date when value in a column is filled

  1. #1
    Registered User
    Join Date
    11-24-2015
    Location
    US
    MS-Off Ver
    Office 2014 Mac
    Posts
    3

    Autosort all data by date when value in a column is filled

    Newbie to vba..

    I have a spreadsheet where I'm looking to autosort all columns from A2:AS5000, by date (column B2:B5000), when the value in column AS is non-blank.
    AS currently contains a formula that says it will remain blank unless all columns from A:AM contains data.

    So the flow I'm trying to achieve is:
    - user enters data in all columns A:AM
    - AS then changes from blank to data
    - All data from A:AS autosorts by date. Date is entered in column B.

    I've literally spent the last few hours on google and here reading old threads and trying to see if I could replicate some of the VBA codes I'm seeing. Unfortunately, i've been unsuccessful.

    Any help in setting up the right VBA code would be greatly appreciated. I'm using Office 2016 for Mac.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Autosort all data by date when value in a column is filled

    Hi,

    You seem to be suggesting that the sort is conditional on AS. i.e. you don't want to sort any rows where AS is blank. Is that the case?
    If so then two sort keys are needed.

    The first sort key is AS which should be sorted Z-A and the second key is column B sorted ascending.

    What's unclear is what's the trigger for this? Just because a cell formula reflects a different value won't of itself be able to trigger a sheet change macro. You could use an actual change to columns A-AM as a trigger, or just have a macro linked to a button which would resort when you clicked the button.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-24-2015
    Location
    US
    MS-Off Ver
    Office 2014 Mac
    Posts
    3

    Re: Autosort all data by date when value in a column is filled

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    You seem to be suggesting that the sort is conditional on AS. i.e. you don't want to sort any rows where AS is blank. Is that the case?
    If so then two sort keys are needed.
    Thanks for your reply Richard.

    If a cell in column AS is blank, then that corresponding row across columns A-AM will also be blank so nothing to sort really. AS is really a helper column that validates that the user entered info in all columns A-AM across a single row (and will be used in another formula).


    Quote Originally Posted by Richard Buttrey View Post
    What's unclear is what's the trigger for this? Just because a cell formula reflects a different value won't of itself be able to trigger a sheet change macro. You could use an actual change to columns A-AM as a trigger, or just have a macro linked to a button which would resort when you clicked the button.
    If I understand you correctly, a macro can't be triggered by a cell changing value driven by a formula (from blank to not blank) but can be triggered by an actual entry of data into that cell?

    My intent is that once the user fills all columns A-AM that then the data gets autosorted. So my thought was to put something that calculates if A-AM is filled, then that will cause the autosort to happen.

  4. #4
    Registered User
    Join Date
    11-24-2015
    Location
    US
    MS-Off Ver
    Office 2014 Mac
    Posts
    3

    Re: Autosort all data by date when value in a column is filled

    Figured it out myself. For anyone interested, here's what I did....

    - Recorded a macro of me filtering the date column in descending order.
    - Go to VBA editor, go to the module created for the recorded macro, then copied to VBA code.
    - Googled "vba code on cell value change"
    - Found this and modified it:

    Please Login or Register  to view this content.


    Worked like a charm.

+ 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. Macro to enter data in next column if previous column is filled.
    By NIKNIKNIK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-15-2014, 11:26 AM
  2. [SOLVED] stream gage data need a seasonal column filled based on the date (macro)
    By shivernoz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2014, 03:06 PM
  3. [SOLVED] Formula to return first date where column planned is filled
    By Risto85 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 08-23-2013, 03:07 AM
  4. [SOLVED] Find last filled row in column where column description is date
    By Risto85 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-28-2013, 08:02 AM
  5. Replies: 4
    Last Post: 12-04-2012, 02:24 AM
  6. VBA Code to copy data from last filled column and paste to the next available column.
    By Pavman2473 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2012, 09:07 PM
  7. Replies: 11
    Last Post: 06-05-2011, 11:30 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