+ Reply to Thread
Results 1 to 11 of 11

Making rows invisible with VBA

  1. #1
    Registered User
    Join Date
    07-25-2008
    Location
    Irvine
    Posts
    7

    Making rows invisible with VBA

    Hi, I have a cell range from A18 to A49, and I want a macro to hide the rows that have zeros in them. For example, if the value on A24 is zero, row 24 would be hidden. But if the value on A24 changes to a number later, row 24 would show up again.

    Now I guess you can already tell I am a beginner at VBA. I thought of a macro like this:

    Please Login or Register  to view this content.
    But repeating those lines from A18 to A49 seems pretty tedious. Is there a faster way to do this?
    Last edited by teylyn; 05-08-2010 at 02:13 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Making rows invisible with VBA

    Your post does not comply with Rule 3 of our Forum RULES. 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 # at the top of your post window. For more information about these and other tags, found here

    Code tags added this time only.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Making rows invisible with VBA

    How does the value of a hidden cell change?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Making rows invisible with VBA

    try this (given the values in A are determined by a formula and the macro is kicked off manually)

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-25-2008
    Location
    Irvine
    Posts
    7

    Re: Making rows invisible with VBA

    Thanks teylyn, it worked very well!

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Making rows invisible with VBA

    How will the cell values change?

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Making rows invisible with VBA

    Roy, in my scenario I decided that the cell values were determined by formulas, so the problem of accessing a hidden cell to change its value back to something other than zero did not manifest.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Making rows invisible with VBA

    I realise it would probably be a formula, in which case the calculate event could trigger the change.

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Making rows invisible with VBA

    True. I have not used that event so far, but will expand my horizon.

    So, something like this in the Sheet module

    Please Login or Register  to view this content.
    Last edited by teylyn; 05-08-2010 at 03:26 AM.

  10. #10
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Making rows invisible with VBA

    Can shorten the code a wee bit just using:

    Please Login or Register  to view this content.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  11. #11
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Making rows invisible with VBA

    Palmetto,

    good point. To clarify for the OP's benefit (and to reinforce my own learning):

    the code bit ...

    Please Login or Register  to view this content.
    ... will result in eithert TRUE or FALSE, thus yielding

    Please Login or Register  to view this content.
    Nice!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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