+ Reply to Thread
Results 1 to 5 of 5

Filter by month (not as a string) using VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    England
    MS-Off Ver
    2016 (Mac)
    Posts
    149

    Filter by month (not as a string) using VBA

    Hello everyone,

    I am trying to get VBA to filter based on the month. So a user inputs "March" into cell R2 and cell R1 has the following formula in:
    =MONTH(1&R2)
    this equals to 3 (March). VBA will take the value of cell R1 (3 (March)) and filter column B for any entries with March in.

    I am attaching a spreadsheet in case my explanation does not make much sense. There is a small VBA code in the sheet that filters by the month as a string but it does not work because the dates in column B are not entered as strings.

    Thank you for any help,

    Margate
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,623

    Re: Filter by month (not as a string) using VBA

    1) Select A1:O1 [Unmerge]
    2) Delete row(2), merged cell(s) are just creating problems in data manipulating process.
    3) Clear R1:R2, enter formula
    =MONTH(B2)=3
    in R2
    4) Select A1 and [Data] - [Advanced]
    5) Select R1:R2 for [Criteria Range] then hit [OK]

  3. #3
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Filter by month (not as a string) using VBA

    Alternately, how about a helper column (example: P3=MONTH(B3) then copy down).

    Change code line from
    ActiveSheet.Range("$B$3:$B$2002").AutoFilter Field:=2, Criteria1:="=*" & Sheets("Bookings").Range("R2").Value & "*", Operator:=xlAnd
    
    to
    
    ActiveSheet.Range("$A$1:$P$1517").AutoFilter Field:=16, Criteria1:=Sheets("Bookings").Range("R1").Value
    This will filter all records to the month number calculated in R1.

    HTH,
    Maud

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,623

    Re: Filter by month (not as a string) using VBA

    Margate

    Thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  5. #5
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Filter by month (not as a string) using VBA

    Margate,

    Thank you as well for the rep and you are most welcome.

    Maud

+ 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] Want to filter multiple string using comma with textbox as i filter
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2017, 09:29 AM
  2. Pivot Filter not allowing filter by year, month and date
    By Steve aka Munky in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 02-17-2017, 11:47 AM
  3. Auto-Filter Pivot Table with New Month filter
    By eskyec in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-06-2013, 06:05 PM
  4. How to filter exact string within another string???
    By ray1202 in forum Excel General
    Replies: 2
    Last Post: 08-31-2010, 07:47 PM
  5. Replies: 3
    Last Post: 04-17-2010, 05:02 AM
  6. Filter Partial string, send to "Filter Sheet"
    By davemcochrane in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-13-2008, 11:28 AM
  7. MONTH as a string
    By facmess1 in forum Excel General
    Replies: 3
    Last Post: 12-05-2006, 03:37 PM

Tags for this Thread

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