+ Reply to Thread
Results 1 to 7 of 7

VBA for Autohiding empty rows

  1. #1
    Registered User
    Join Date
    10-12-2011
    Location
    Police State of DC
    MS-Off Ver
    Excel 2010
    Posts
    8

    VBA for Autohiding empty rows

    I've got a spreadsheet using VBA to autohide blank rows. Code is working on one worksheet, and 'error 13' on two others: anyone interested in helping to resolve??

    Not a competent VBA user and sourced the code from the web. So trying to debug has proved incredibly difficult as I am unsure of what the code means! (It also doesn't work too fast)

    Also note that the rows are not 'blank' as they are conditionally pulling data from a root worksheet - naturally, some rows do not meet the criteria and look empty though are technically " " (if this is helpful)... I do like the way the current version runs when the worksheet is activated!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: VBA for Autohiding empty rows

    You are probably recieving an error because you are trying to sum strings; excel can't calculate dave+gugg+89, the data has to all be numbers. Normally, you'd use the CountA() function to check the number of cells that aren't blank, but this won't work if you are using formulas. I believe you are going to have to loop through each cell in each row and check if there is no value. This is going to take longer to run:

    Please Login or Register  to view this content.
    I'd also like to add that storing a lone space in a cell (" ") is poor practice; there is no easy way to discern whether the cell is holding data or not. Better would be to use a blank ("").
    Last edited by davegugg; 10-12-2011 at 02:42 PM. Reason: Forget End If
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    10-12-2011
    Location
    Police State of DC
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA for Autohiding empty rows

    Great explanation. In fact I really only need to have the first column analyzed: if this column does not contain a number >>> the entire row is void and should be hidden. Would that make things easier?

    Also, when i pasted the code in i received "Next without For" compile error...



    Regarding the " ", was a typo and is in fact a "" blank.

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: VBA for Autohiding empty rows

    Ok, if you only need to check the first column, you can shorten it up nicely:

    Please Login or Register  to view this content.

    I've also edited my code in post 2 to fix the End If I missed, so that should work properly now if you should need to check across the entire row in the future.

  5. #5
    Registered User
    Join Date
    10-12-2011
    Location
    Police State of DC
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA for Autohiding empty rows

    Code in Post 2 does the job nicely! Almost in disbelief after how many hours I've spent...

    Code in post 4 needs definition for HiddenRow. Should I include a 'Dim HiddenRow As Integer' as in Post 2?

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: VBA for Autohiding empty rows

    That should probably be there. Although defining the variables isn't required in VBA, most people (me included) consider it a good practice. The reason VBA stopped you is because you have marked Option Explicit, which forces you to define all variables.

  7. #7
    Registered User
    Join Date
    10-12-2011
    Location
    Police State of DC
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA for Autohiding empty rows

    SOLVED, thank you so much! Working like a charm.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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