+ Reply to Thread
Results 1 to 9 of 9

Hide Rows using a Macro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Hide Rows using a Macro

    I have several hundred spread sheets coming to me for analysis, the layout is identical on each one. I need to hide particular rows on every single sheet, e.g. Rows 14, 16, 17, 18, and 46 to 51 inclusive. Is there anyway to do this using a macro so I don't have to laboriously do this every time I open each sheet?

    Many thanks

  2. #2
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Hide Rows using a Macro

    Hello
    Is that the same rows on each spreadsheet or do you need to choose which rows based on some criteria ?

    If same row you could specific that and run a little macro to clean that out :

    Sub test()
        hide_row = Array(14, 16, 17, 18, 46, 47, 48, 49, 50, 51)
        Range("A1").Select
        
        For n = 0 To 9
            ActiveCell.Offset(hide_row(n), 0).EntireRow.Delete
        Next n
        
    End Sub
    Regards

  3. #3
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Hide Rows using a Macro

    Hello
    That deletes the row, you can change that to hide the row, probably need another line of code for that.

    Regards

  4. #4
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Hide Rows using a Macro

    Hi hamjam,

    Yes, it would be the same rows on each spreadsheet, but it would definitely need to hide the rows and now delete them, is that possible to do?

    Many thanks

  5. #5
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Hide Rows using a Macro

    One more tip, I would create an empty spreadsheet with the macro and save the activation of the macro under the event of opening a file. Then I would open the spreadsheets from that template.
    In this case, the macro would run automatically and the rows would be removed when it displays in front of you.

    Just throwing it out there.

    Regards

  6. #6
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Hide Rows using a Macro

    Hello
    Most things are possible ....

    Just change the line in the middle to read :
            ActiveCell.Offset(hide_row(n) - 1, 0).EntireRow.Hidden = True
    I also added a '-1' as otherwise you would miss the row by 1 line every time.

    Regards

  7. #7
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Hide Rows using a Macro

    That works perfectly, many thanks...

    You'll have to excuse my ignorance, I think your tip is perfect and will certainly save a lot of time, but how would I actually do that, I'm still very new to VBA!

    Regards

  8. #8
    Forum Contributor
    Join Date
    01-07-2013
    Location
    south africa
    MS-Off Ver
    Excel 2003-13
    Posts
    210

    Re: Hide Rows using a Macro

    Hello
    Perhaps you could mark above as solved. And stars are always welcome.

    For the tip, it is a little tricker. In the VBA editor (alt F11) instead of the module where your code is inserted, go up an you will find "thisworkbook". It you double-click it, it should open a blank screen on youur right side with the top left (also called object) saying workbook
    If you look to the right of it, another text box show (called procedure)

    You can change the procedure to open and then a bit of code appear below. This is the code that will be run when the workbook is opened. You will have to add some code in between the sub and end sub, on the lines of :
        fileToOpen = Application.GetOpenFilename()
        Workbooks.Open Filename:=fileToOpen
    And also add the name of the macro, my name was test - as the 3rd line

    Play around a bit with that, it may save you some time later.

    Regards

  9. #9
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Hide Rows using a Macro

    Thanks hamjam, I'll give that a go, I think it is a perfect idea...

    Many thanks for your help...

+ 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