+ Reply to Thread
Results 1 to 5 of 5

Hiding and Unhiding rows based on their dates VBA

  1. #1
    Registered User
    Join Date
    10-15-2015
    Location
    United States
    MS-Off Ver
    2013
    Posts
    4

    Hiding and Unhiding rows based on their dates VBA

    Hi everyone! New to VBA and trying to teach myself (unsuccessfully). I want to hide individual rows in a range from 6-36 based on dates in those rows being greater than or equal to a reference cell that changes daily based on a formula (today()-1). i have attached an example of my worksheet to show what i am working with and showing what i would like it to do. Just don't know how to get there using code.

    Any help is much appreciated!

    Book..xlsx

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

    Re: Hiding and Unhiding rows based on their dates VBA

    One line of code should do it - always try to use native Excel functionality when you can, and record macros to then modify to what you need

    Please Login or Register  to view this content.
    Note that "< today" is the same as "<=today -1"
    Last edited by Bernie Deitrick; 10-15-2015 at 03:43 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Hiding and Unhiding rows based on their dates VBA

    Perhaps you could use the active line in Bernie's sub in a "Private Sub Workbook_Open()", this way the macro will run whenever you opens the workbbok.

    Ooooooooops my bad! In the Visuasl Basic Window right click on "ThisWorkbook", then click on "View Code" and paste this code in the new windows that opends.

    Please Login or Register  to view this content.
    Alf
    Last edited by Alf; 10-15-2015 at 04:55 PM.

  4. #4
    Registered User
    Join Date
    10-15-2015
    Location
    United States
    MS-Off Ver
    2013
    Posts
    4

    Re: Hiding and Unhiding rows based on their dates VBA

    That works great! The only thing is when I apply it to my actual data it puts the filters at the top of the page (row 1) and hides my headers.. but when I applied it to my example sheet it put the filters on row 5 and kept the headers.. any idea as to why this is? I'm sure i can find a work around if there is no other way.

    Again thank you for the help!!

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

    Re: Hiding and Unhiding rows based on their dates VBA

    You need to have an entirely blank row 4 - any contiguously filled cells will allow the current region method to select up to row 1. If you don't want to empty out row 4, insert a new row 5 and change the code to

    ActiveSheet.Range("$A$6").CurrentRegion.AutoFilter Field:=6, Criteria1:="<" & Date

    or use

    ActiveSheet.Range("$A$1").CurrentRegion.Offset(4).AutoFilter Field:=6, Criteria1:="<" & Date

    but then make sure that you do have a contiguous path from A1 to the data set.

+ 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] hiding/unhiding rows based on a selection from a drop down
    By jenetic03 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-22-2014, 10:49 AM
  2. Hiding and unhiding rows based on number of cell values
    By juliettelam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2014, 07:48 PM
  3. Hiding and unhiding rows based on a CountA value
    By juliettelam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2014, 12:23 PM
  4. [SOLVED] Help hiding/unhiding rows based on multiple responses
    By mglitter1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2013, 07:11 PM
  5. [SOLVED] Unhiding / Hiding rows based on a different cell value
    By gm2612 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-30-2013, 05:15 AM
  6. [SOLVED] Hiding/Unhiding Rows Based on Dropdown Box
    By SubParLlama in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-14-2012, 12:29 PM
  7. Hiding Unhiding Rows based on Text condition
    By Winner_texas in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-11-2010, 11:54 AM

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