+ Reply to Thread
Results 1 to 4 of 4

Macro code to filter for the end date of the previous month

  1. #1
    Registered User
    Join Date
    03-10-2020
    Location
    Hong kong
    MS-Off Ver
    MAC 2008
    Posts
    25

    Lightbulb Macro code to filter for the end date of the previous month

    Hi Everyone

    I am relatively new to VBA

    I have a table with around 20 columns, one of them displays the latest available date of the performance data, because the performance data for the structured derivatives I am measuring do not usually get updated all in one go as of the same date, I want to be able to use a macro to filter out all the up to date structured derivatives, which is filtered by the end date of the previous month.

    I know the excel formula is =EOMONTH(TODAY(),-1)
    How can I design a macro with the formula above and assign a button to it.

    Thanks!!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Macro code to filter for the end date of the previous month

    Use code like this, for dates in column B (the 2 in Array(2, means the second column in the filtered range.

    Please Login or Register  to view this content.
    You can also record a macro, and replace the selected date (like "2/29/2020") with DateSerial(Year(Date), Month(Date), 0)
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    03-10-2020
    Location
    Hong kong
    MS-Off Ver
    MAC 2008
    Posts
    25

    Re: Macro code to filter for the end date of the previous month

    Attachment 669998

    I actually have a table in place, for some reason, an error is popping up after I try to incorporate your macro, would you be able to help!

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: Macro code to filter for the end date of the previous month

    Tables require different code, along the lines of

    Please Login or Register  to view this content.
    Really, the thing to do is to record a macro where you select the date column and filter for any single date, then stop the recording. The replace the date string in the code with

    Please Login or Register  to view this content.

+ 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. Filter Pivot by Previous Month
    By Oxygen Potassium in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-16-2019, 03:47 PM
  2. [SOLVED] Macro Filter Month by Date
    By Berna11 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-11-2017, 11:43 AM
  3. Macro for applying filter for previous month's data
    By aaron1976 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-21-2015, 06:29 PM
  4. [SOLVED] Filter for the previous month only - Pivot VBA
    By BrianBrian76 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-15-2015, 05:12 AM
  5. VBA code adjustment to include only current month and previous month automatically.
    By ElmerFud in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-05-2015, 03:02 PM
  6. Replies: 5
    Last Post: 10-04-2012, 07:06 AM
  7. [SOLVED] Code to auto filter three month segments of data from today's date
    By gryffin13 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2012, 04:51 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