1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

macro to hide/unhide cells

Discussion in 'Business Applications' started by aviflux, Oct 16, 2008.

Thread Status:
Not open for further replies.
  1. aviflux

    aviflux Thread Starter

    Oct 15, 2008

    Yesterday I created a code that hides/unhides rows when checkbox is clickedand goes something like this:

    Rows("22:24").EntireRow.Hidden = Not Rows("22:24").EntireRow.Hidden

    But now i only want to hide/unhide specified cells. So how can i modify the code above to do this or do I need some new code.

    Thanks for help :)
  2. MRdNk


    Apr 7, 2007
    "hide/unhide specified cells" - I take it, you mean rows, not cells.

    What's your criteria for hiding/unhiding the row? All you need to do is loop through each row in your criteria column, and then program this in as your hide/unhide criteria.

    Pseudo Code:
    Sub hideAndUnhide()
    [INDENT]For Each Cell In Range("A1",Range("A1").End(xlDown))
    [INDENT]If(Cell.Value = 1) Then 
    [INDENT]Rows(Cell.Row).EntireRow.Hidden = True [/INDENT]
    [INDENT]Rows(Cell.Row).EntireRow.Hidden = False[/INDENT]
    End If[/INDENT]
    Next Cell
    End Sub
    If you let me know your data layout, and your criteria, I should be able to make a proper version for you. Even better would be to post your excel sheet with dummy data (remove any sensitive data).
  3. slurpee55


    Oct 20, 2004
    Just to clarify on what MrdNK was saying, you can't hide single cells. You can only hide columns or rows.
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/759698

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice