+ Reply to Thread
Results 1 to 7 of 7

Macro command button to hide empty rows

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    High Wycombe, England
    MS-Off Ver
    Excel 2010
    Posts
    46

    Macro command button to hide empty rows

    I have a master worksheet which will copy data from several pages on a if lookup formula, if it fails it puts "" in instead.

    Can someone help me with the code for a macro that will hide each row if the cell in column A contains "".

    The macro will be attached to a command button, so will either need to have a 1 click to hide, second click to unhide. Or have 2 buttons.

    I'm not sure if I've explained myself, if not please let me know and I will try to clarify.

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro command button to hide empty rows

    A couple of comments. (1) Since you are already coding with VBA, why not use VBA to extract your information rather than use Lookups that will have blank rows? (2) If you do need the formulas, can you post a sample of your workbook so we can more easily code this for you?

  3. #3
    Registered User
    Join Date
    08-20-2012
    Location
    High Wycombe, England
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Macro command button to hide empty rows

    Honestly, as I've had a lot less experience with macros, so I tend to use formula when I can.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro command button to hide empty rows

    Add a togglebutton to your sheet, and use the code in the Click event

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-20-2012
    Location
    High Wycombe, England
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Macro command button to hide empty rows

    I've got this error message :Serror message.jpg

  6. #6
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Macro command button to hide empty rows

    Djauncey,

    The code SHOULD work, and in fact did work on a test sheet that I worked with. If you are having problems, can you possibly post a copy of the workbook?

    Also, I noticed an error in the code. In the code I wrote, I used the line:
    Please Login or Register  to view this content.
    to determine the last row of your range. This allows us to use a dynamic range and NOT use a fixed range.

    That said, the following code checks expands the range to the used range within the worksheet:
    Please Login or Register  to view this content.
    THe range is now A3 to A and the last row. In your code, you used
    Please Login or Register  to view this content.
    Essentially, you used BOTH a fixed range AND the variable, which MAY be the cause of the problems. Amend that and see if it helps. If not, then post a copy of the book.

  7. #7
    Registered User
    Join Date
    08-20-2012
    Location
    High Wycombe, England
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Macro command button to hide empty rows

    Hi BigBas, thanks for the help so far. I've got it working which is good.

    1 final question, is it possible to have it set up so the first click hides those cells and then the second click shows them again?

+ 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