+ Reply to Thread
Results 1 to 3 of 3

Macro to Hide/Unhide Rows Based on Cell Value

Hybrid View

  1. #1
    Registered User
    Join Date
    11-10-2015
    Location
    San Francisco, California
    MS-Off Ver
    2013
    Posts
    11

    Macro to Hide/Unhide Rows Based on Cell Value

    I have a dynamic spreadsheet and I would like a macro that will automatically hide a row when all values in that row from a given column range are 0 or blank (whichever works, I can leave the cells blank or insert a 0 if need be). I would also need a macro to automatically unhide a row if any of the cells in a given column range contain values greater than 0 and I would like this to update automatically.

    For example, row 16 in my attachment currently contains no values from columns B to O, so I would like the macro to automatically hide that row. If I went in and entered a number 3 in D16, I would want the macro to unhide the entire row. Is this possible? Please let me know if what I'm asking is not clear enough.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Macro to Hide/Unhide Rows Based on Cell Value

    with this code in SheetChange

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column > 1 And Target.Column < 16 And Target.Count = 1 Then
        Application.ScreenUpdating = False
        lr = Range("A" & Rows.Count).End(xlUp).Row
        For x = lr To 4 Step -1
            If Application.Sum(Range("B" & x, "O" & x)) = 0 Then
                Range("A" & x).EntireRow.Hidden = True
            Else: Range("A" & x).EntireRow.Hidden = False
         End If
        Next
        Application.ScreenUpdating = True
    End If
    End Sub
    Kind regards
    Leo
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-10-2015
    Location
    San Francisco, California
    MS-Off Ver
    2013
    Posts
    11

    Re: Macro to Hide/Unhide Rows Based on Cell Value

    Thank you so much!

+ 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] Macro to unhide & hide rows based on column value
    By qvfr034 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-15-2020, 03:00 PM
  2. VBA to hide and unhide rows based on a cell value in the row
    By Preacher63 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2015, 04:13 PM
  3. [SOLVED] Macro to automatically hide or unhide rows based on either a value or no value in a cell
    By WFP111 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2013, 12:28 PM
  4. simple macro to hide or unhide rows based on a cell value
    By Russ Fuquay in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2013, 06:32 PM
  5. Macro to Hide/Unhide Multiple Rows Based on Cell Value
    By mbp727 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2013, 11:12 AM
  6. Hide/Unhide rows based on Cell Value
    By noelwri in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2012, 04:25 PM
  7. Hide/Unhide Rows Based On Cell Value
    By ZooTV92 in forum Excel General
    Replies: 5
    Last Post: 09-05-2011, 07:51 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