+ Reply to Thread
Results 1 to 12 of 12

Excel 2007 : VB code to hide rows that are empty or contain "-"

  1. #1
    Registered User
    Join Date
    07-26-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    VB code to hide rows that are empty or contain "-"

    Hi folks,

    Need some help with VB function to hide rows based on a value in a column defined.
    The function should evaluate on the first column and it will loop through all rows in the template range. If the cell evaluate to 0, then it suppress the row, otherwise, it leave it.

    I need the function to be generic and work on any worksheet.

    Any help is much appreciated to get me started.

    Thanks in advance!!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VB code to hide rows that are empty or contain "-"

    It helps to know how the values in that column get there, by manual insertion or by formula. But a generic way to examine all of column A on a given sheet would be:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: VB code to hide rows that are empty or contain "-"

    Is there a reason for not just using an autofilter?
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    07-26-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: VB code to hide rows that are empty or contain "-"

    Thanks for the feed back folks. I'm new with VB. I'm using the following code (as it's the only one i seem to understand) but I get an error when I try to compile it. By the way the object is sheet1.

    Run-Time error '424, Object required
    Please Login or Register  to view this content.
    Last edited by romperstomper; 09-22-2010 at 06:29 PM. Reason: add code tags

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: VB code to hide rows that are empty or contain "-"

    What is Template supposed to be?

    Also, you must use code tags when posting code on the forum. I have added them for you on this occasion, but you must use them yourself in future, please.

  6. #6
    Registered User
    Join Date
    07-26-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: VB code to hide rows that are empty or contain "-"

    okay i removed the Template and not got a different error. Error 438, Object doesn't support this property or method. added quoted text around my code, hope that is what you meant by code tags.

    Please Login or Register  to view this content.
    Last edited by ironmonkey888; 09-23-2010 at 12:04 AM.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: VB code to hide rows that are empty or contain "-"

    Highlight your code and click the # at the top of your post window. For more information about these and other tags, see here

    You can also just type them in:
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]

  8. #8
    Registered User
    Join Date
    07-26-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: VB code to hide rows that are empty or contain "-"

    moved to excel programming page ....

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: VB code to hide rows that are empty or contain "-"

    Your unprotect and protect part is incorrect - it should be:
    Please Login or Register  to view this content.
    and:
    Please Login or Register  to view this content.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: VB code to hide rows that are empty or contain "-"

    Why are you looping through the columns when you hide the entirerow?
    Cheers
    Andy
    www.andypope.info

  11. #11
    Registered User
    Join Date
    07-26-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: VB code to hide rows that are empty or contain "-"

    Tried your suggestion but i still get the same error.

    I only want to loop through the first column as there will be a formula that will return x if there is not data. I see what your mean. how do i modify my code to only loop through column 1?

    thx
    Last edited by ironmonkey888; 09-23-2010 at 10:20 AM.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: VB code to hide rows that are empty or contain "-"

    What did you actually try?

+ 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