+ Reply to Thread
Results 1 to 5 of 5

Need to Hide/Unhide Rows and Columns Based on Several Date Ranges

Hybrid View

  1. #1
    Registered User
    Join Date
    03-19-2014
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Need to Hide/Unhide Rows and Columns Based on Several Date Ranges

    Hello,

    I am very new to VBA. I am building a sheet to display deadlines (rows) by project (columns). I would like to have it automatically hide the rows and columns based on the date of the deadline. If the deadline is today or 1 week from today the associated rows and columns should be visible, otherwise, I would like to hide them.

    My table is A1:N9, with A1 being a blank, row names A2:A9, and column names B1:N1.

    Any help would be greatly appreciated.

    Thank you!

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Need to Hide/Unhide Rows and Columns Based on Several Date Ranges

    it would help us a lot if you could attach a workbook with your actual layout. Put some non-sensitive data in it to show us what it looks like. It is not clear to me right now as how you data are arranged, although I can imagine. But who would loose its time to work on an assumption. Right?
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    03-19-2014
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Need to Hide/Unhide Rows and Columns Based on Several Date Ranges

    sample.xlsx

    Sure - thanks for the reply!

  4. #4
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Need to Hide/Unhide Rows and Columns Based on Several Date Ranges

    Look at the attached workbook for 2 macros. One will hide or show columns and rows based on today's date. The other one will unhide all columns and rows so you can work on your table.
    Here is the code:
    Public Sub HIde_OR_Show()
    Dim C_ell As Range, Col_Rng As Range, Proj_is_due As Boolean
    Dim Row_Rng As Range
    Application.ScreenUpdating = False
    'Lets start with the columns
    For Each Col_Rng In Range("B1", Cells(1, Columns.Count).End(xlToLeft))
       Proj_is_due = False
       For Each C_ell In Range(Col_Rng.Offset(1), Cells(Rows.Count, Col_Rng.Column).End(xlUp))
          If C_ell >= Int(Now()) And C_ell < Int(Now()) + 7 Then
             Proj_is_due = True
          End If
       Next
       If Proj_is_due Then
          Col_Rng.EntireColumn.Hidden = False
       Else
          Col_Rng.EntireColumn.Hidden = True
       End If
       Proj_is_due = False
    Next
    'Here we do the rows
    For Each Row_Rng In Range("A2", Cells(Rows.Count, 1).End(xlUp))
       Proj_is_due = False
       For Each C_ell In Range(Row_Rng.Offset(0, 1), Cells(Row_Rng.Row, Columns.Count).End(xlToLeft))
          If C_ell >= Int(Now()) And C_ell < Int(Now()) + 7 Then
             Proj_is_due = True
          End If
       Next
       If Proj_is_due Then
          Row_Rng.EntireRow.Hidden = False
       Else
          Row_Rng.EntireRow.Hidden = True
       End If
       Proj_is_due = False
    Next
    Application.ScreenUpdating = True
    End Sub
    
    Public Sub Unhide_All()
    Cells.EntireRow.Hidden = False
    Cells.EntireColumn.Hidden = False
    End Sub
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-19-2014
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Need to Hide/Unhide Rows and Columns Based on Several Date Ranges

    Thank you so much - that was very helpful!

+ 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] Checkbox VBA - Hide/Unhide Rows and/or Columns based on cell values
    By gravy258 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-21-2013, 05:39 PM
  2. Excel Hide/Unhide Rows/Columns
    By jregan in forum Excel General
    Replies: 4
    Last Post: 08-03-2010, 11:55 AM
  3. How to hide and unhide Rows & Columns
    By Aarif in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-23-2006, 01:25 AM
  4. [SOLVED] How do I hide or unhide zero value columns/rows USING A MACRO?
    By paul in forum Excel General
    Replies: 1
    Last Post: 01-23-2006, 11:10 AM
  5. Hide / Unhide columns and rows
    By PaulM in forum Excel General
    Replies: 8
    Last Post: 12-12-2005, 11:10 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