+ Reply to Thread
Results 1 to 15 of 15

VBA hide/unhide rows containing 0's

  1. #1
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    VBA hide/unhide rows containing 0's

    Hi all,

    I've managed to have the below work for a specific column, how would I go about adding additional columns? Apologies as I'm fairly green with this!

    Option Explicit

    Sub hideUnhideZeros()
    Dim rng As Range
    Dim R As Long
    Dim RwCnt As Long

    Set rng = ActiveSheet.Range(Cells(1, 5), Cells(Rows.Count, 5).End(xlUp))
    RwCnt = rng.Rows.Count

    For R = RwCnt To 1 Step -1
    If Cells(R, 5).Value = 0 Then Cells(R, 5).EntireRow.Hidden = Not Cells(R, _
    5).EntireRow.Hidden
    Next R
    End Sub


    Thanks in advance.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: VBA hide/unhide rows containing 0's

    Hi donjamin

    Welcome to the forum.
    In future please view the forum rules before posting. Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window.
    Are you wanting to add more columns to run check if value = 0 other than column E
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    Re: VBA hide/unhide rows containing 0's

    My apologies, yes effectively I am needing to run the check for columns F and G.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: VBA hide/unhide rows containing 0's

    So if either cells in E or F or G columns contain 0 the hide rows

  5. #5
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    Re: VBA hide/unhide rows containing 0's

    Just F and G please, disregard column E for the moment.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: VBA hide/unhide rows containing 0's

    Try this
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    Re: VBA hide/unhide rows containing 0's

    Thanks Sintek, it doesn't appear to be unhiding the rows for me.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: VBA hide/unhide rows containing 0's

    Are you trying to hide the rows if cell value = 0

  9. #9
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    Re: VBA hide/unhide rows containing 0's

    Yes Sintek, it works to hide the cells appropriately, it just doesn't unhide them when the macro is run again as the code I provided initially does.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: VBA hide/unhide rows containing 0's

    Now I understand, sorry:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    Re: VBA hide/unhide rows containing 0's

    Thanks Sintek, marked as solved and added to your reputation. Much appreciate the help!

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: VBA hide/unhide rows containing 0's

    Pleasure...Thanks for rep points

  13. #13
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    Re: VBA hide/unhide rows containing 0's

    Actually have encountered an unfortunate issue with this code. Rows that contain a 0 in both columns are not filtered out when this macro is used. Any ideas on how to resolve this?

  14. #14
    Registered User
    Join Date
    04-27-2017
    Location
    London
    MS-Off Ver
    MS Office 2013
    Posts
    38

    Re: VBA hide/unhide rows containing 0's

    Anyone have a solution for my last comment? Much appreciate the help!

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,168

    Re: VBA hide/unhide rows containing 0's

    This one has me slammed.....Anyone able to assist...have tried various options and still no result found.

+ 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 for Hide blank rows and Unhide the rows with cells
    By Neilesh Kumar in forum Excel General
    Replies: 4
    Last Post: 04-12-2017, 06:06 AM
  2. Need Toggle Button to hide/unhide rows based on cell value in non concurrent rows
    By The Phoenix in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-13-2015, 10:49 AM
  3. Add Hide\UnHide Rows to this
    By welshman010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2014, 06:55 PM
  4. [SOLVED] First unhide all rows - then hide rows based on specific cell value for a range of cells
    By robbiekh in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-22-2013, 05:46 PM
  5. VBA hide/unhide rows
    By telnoman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-18-2010, 08:58 AM
  6. Hide & Unhide Rows
    By Willman in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-14-2006, 04:19 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