+ Reply to Thread
Results 1 to 4 of 4

Need to tweak code...Hide Rows Based on Cell Value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-18-2009
    Location
    Winnipeg
    MS-Off Ver
    Excel 2003
    Posts
    203

    Need to tweak code...Hide Rows Based on Cell Value

    I have the code below hiding columns based on the value in the respective cells.

    Now I need to adjust this so it will also hide rows A9:A16 based on their cell values. They will either be blank or will say "HIDE" if that row needs to be hidden.

    Private Sub Worksheet_Calculate()
    Dim rCell As Range
    For Each rCell In Range("D1:L1")
    rCell.EntireColumn.Hidden = (rCell.Value = "HIDE")
    Next rCell
    End Sub
    Last edited by kmlloyd; 07-21-2015 at 11:06 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,698

    Re: Need to tweak code...Hide Rows Based on Cell Value

    Try this:

    Private Sub Worksheet_Calculate()
    Dim rCell As Range
    For Each rCell In Range("D1:L1")
    rCell.EntireColumn.Hidden = (rCell.Value = "HIDE")
    Next rCell
    
    For Each rCell In Range("A9:A16")
    rCell.EntireRow.Hidden = (rCell.Value = "HIDE")
    Next rCell
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    11-18-2009
    Location
    Winnipeg
    MS-Off Ver
    Excel 2003
    Posts
    203

    Re: Need to tweak code...Hide Rows Based on Cell Value

    Thank you. When I use this, it seems to get caught up on something...it's "skipping" like it's trying to do something and then it gets stuck there until I hit Esc and end the execution.

    When I hit Debug, the first instance of "Next rCell" is highlighted.

  4. #4
    Forum Contributor
    Join Date
    11-18-2009
    Location
    Winnipeg
    MS-Off Ver
    Excel 2003
    Posts
    203

    Re: Need to tweak code...Hide Rows Based on Cell Value

    Got it solved:

    Private Sub Worksheet_Calculate()
    Dim rCell As Range
    Application.EnableEvents = False
    For Each rCell In Range("D1:L1")
    rCell.EntireColumn.Hidden = (rCell.Value = "HIDE")
    Next rCell
    
    
    For Each rCell In Range("A9:A16")
    rCell.EntireRow.Hidden = (rCell.Value = "HIDE")
    Next rCell
    Application.EnableEvents = True
    End Sub

+ 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] Hide rows based on cell value - VBA code
    By phbryan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2015, 12:38 PM
  2. Looking for a VBA code to hide rows based on a single cell value
    By Dial1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-30-2013, 07:04 PM
  3. Help: Code to hide multiple rows based on different cell values
    By swamy156 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2012, 04:35 AM
  4. VBA code to hide/show rows based on value in each row
    By KEM4321 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2012, 01:19 PM
  5. Code to show/hide rows based on Y
    By Justinmih in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2011, 06:12 PM
  6. Modify code to hide rows based on the contents in a cell.
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2009, 09:07 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