+ Reply to Thread
Results 1 to 9 of 9

Macros to hide and unhide rows in a table of data which has separate subheadings

Hybrid View

AKOVA Macros to hide and unhide... 12-18-2012, 02:31 AM
JBeaucaire Re: Macros to hide and unhide... 12-18-2012, 04:36 AM
AKOVA Re: Macros to hide and unhide... 12-18-2012, 07:17 PM
AKOVA Re: Macros to hide and unhide... 12-18-2012, 07:19 PM
JBeaucaire Re: Macros to hide and unhide... 12-18-2012, 07:24 PM
AKOVA Re: Macros to hide and unhide... 12-18-2012, 08:13 PM
AKOVA Re: Macros to hide and unhide... 12-18-2012, 10:21 PM
JBeaucaire Re: Macros to hide and unhide... 12-19-2012, 09:52 AM
JBeaucaire Re: Macros to hide and unhide... 12-19-2012, 09:51 AM
  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Macros to hide and unhide rows in a table of data which has separate subheadings

    Hi guys,

    Could someone please help me with this macro.

    I have a table of data from row 129 to 226. in the table it has headings on rows 129, 149 and 215. I want to have two buttons one for Hiding rows with no values in Column D and one to unhide those columns back to normal but to not hide the headings rows.

    I have tried and i cant work it out.

    Thanks

    Adrian

  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: Macros to hide and unhide rows in a table of data which has separate subheadings

    Like so:

    Option Explicit
    
    Sub UnhideRows()
        Range("D129:D226").EntireRow.Hidden = False
    End Sub
    
    
    Sub HideRows()
    Dim MyRange As Range
    
    On Error Resume Next
    Range("D129:D226").EntireRow.Hidden = False
    
    Set MyRange = Range("D130:D148,D150:D214,D216:D226").SpecialCells(xlBlanks)
    If Not MyRange Is Nothing Then MyRange.EntireRow.Hidden = True
    
    End Sub
    _________________
    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
    Registered User
    Join Date
    12-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macros to hide and unhide rows in a table of data which has separate subheadings

    Thanks for your reply but it seems to not be working. The screen is flicking but nothing is happening.

    I have split the 2 codes above into separate modules. I did not however use the "Option Explicit". Was i supposed to?

    Also there is a formula in column D that defaults to 0. Would this make a difference?

  4. #4
    Registered User
    Join Date
    12-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macros to hide and unhide rows in a table of data which has separate subheadings

    oops double post
    Last edited by AKOVA; 12-18-2012 at 07:21 PM.

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

    Re: Macros to hide and unhide rows in a table of data which has separate subheadings

    EVERYTHING makes a difference. A cell with a formula in it is not "blank". Post a workbook and we'll take a look at what you really mean.

  6. #6
    Registered User
    Join Date
    12-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macros to hide and unhide rows in a table of data which has separate subheadings

    Sorry about that. Yes that is the only difference is that the D column is a total $ sum.

  7. #7
    Registered User
    Join Date
    12-18-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macros to hide and unhide rows in a table of data which has separate subheadings

    Ok. I modified the macro a bit and it seems to work but it works very slowly. Anyone know how to change what i did to work quicker?

    Sub HideRows()
    Dim MyRange As Range, MyCell As Range
    
    On Error Resume Next
    Range("D129:D226").EntireRow.Hidden = False
    
    Set MyRange = Range("D130:D148,D150:D214,D216:D226")
    
    If Not MyRange Is Nothing Then
    
    For Each MyCell In MyRange
    If MyCell.Value = "0" Then MyCell.EntireRow.Hidden = True
    Next
    
    End If
    
    End Sub

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

    Re: Macros to hide and unhide rows in a table of data which has separate subheadings

    I use Option Explicit at the top of ALL my modules. This flag basically turns on Excel's "code checker" and points out any variables I fail to declare or mispell, saving me hours of debugging. If you're going to use VBA a lot, I'd have this on all the time. Turn it on permanently here and it adds itself to any module you create/open for the first time:
    Attached Images Attached Images
    Last edited by JBeaucaire; 12-19-2012 at 10:26 AM.

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

    Re: Macros to hide and unhide rows in a table of data which has separate subheadings

    Sub HideRows()
    Dim MyRange As Range, MyCell As Range
    
    Application.ScreenUpdating = False
    
    Set MyRange = Range("D130:D148,D150:D214,D216:D226")
    
    For Each MyCell In MyRange
        MyCell.EntireRow.Hidden = (MyCell.Value = "0")
    Next MyCell
    
    Application.ScreenUpdating = True
    End Sub

+ 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