+ Reply to Thread
Results 1 to 5 of 5

Filter for Last Weekday

  1. #1
    Registered User
    Join Date
    12-26-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    3

    Filter for Last Weekday

    Hey, guys. I'm new here and to VBA so go easy on me I searched the forums but couldn't find exactly what I'm looking for so I thought I'd ask for help.

    I've set up a macro and need it to filter a column for the last weekday. I could have used yesterday except that it would do me no good on Mondays when yesterday would have been a Sunday. So, I need it to filter for the last weekday only. That code that I used is pasted below but continues to get an error message. Any help is very much appreciated.

    ActiveSheet.Range("$A:$AF").AutoFilter Field:=17, Criteria1:=Weekday(Now(), -1)


    Dennis

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Filter for Last Weekday

    A suggestion that you certainly thought about:
    Add an extra column with the weekday and filter on this extra column.

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filter for Last Weekday

    Hi dcoley

    Welcome to the Forum!!!

    I'll go easy on you and remind you to ALWAYS wrap any Code you post in Code Tags

    This Code returns 4 in the immediate window
    Please Login or Register  to view this content.
    This Code returns Wednesday in the immediate window
    Please Login or Register  to view this content.
    Last edited by jaslake; 12-26-2013 at 02:52 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    12-26-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Filter for Last Weekday

    John, thank you for that reply (and for going easy on me). So, I thought that had done the trick, John, but I'm getting no results returned to me, but when I filter it myself I get some returns. What should happen is that on say December 26, 2013 when I run the macro, I want to get the results from only December 25th, 2013. If it happens to fall on a Monday when I run the macro, I want it to pull the results for the previous Friday. Does that make sense?

    For some reason, when I run the macro with the code as you listed above, I get no results at all.

    Because this is a shared spreadsheet and the information is fed into it, I am not at liberty to add another column as was suggested earlier.
    Last edited by dcoley; 12-26-2013 at 04:45 PM.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filter for Last Weekday

    Hi Dennis

    Since I'm working out of context I'm not able to debug the Code. I'll be happy to do so but you'll need to post a sanitized version of your File. To do so...

    [Canned Reply]
    Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" worksheet (if appropriate) that demonstrates what you wish the output to be.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the "Add Files"... button to locate your file for uploading.
    6. This will open a new window File Upload...Click "Select Files"
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the "Upload Files" button and wait until the file has uploaded.
    10. Click the "Done" Button.

+ 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] how to get weekday ?
    By ks1102 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-10-2013, 06:44 AM
  2. weekday
    By pichai in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-30-2008, 06:32 AM
  3. Weekday
    By Thomas in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-28-2006, 08:50 PM
  4. Weekday
    By GordonY in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-02-2005, 11:18 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