+ Reply to Thread
Results 1 to 26 of 26

Hide, Switch to hidden

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Hide, Switch to hidden

    Hi

    I am stuck.

    How do I hide all EXCEPT selected (highlighted) rows (or columns).

    and then

    Toggle view to hidden or visible back and forth ("Microsoft works" used to do this in the old days...)

    Thanks
    Last edited by drgkt; 10-15-2016 at 05:17 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,730

    Re: Hide, Switch to hidden

    You say it did it in the old days, but your profile suggests you are using an old version: which version are you using?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    "Microsoft works" was a "kind-of-office" package back in windows 3.1.

    Yes, I am requiring an answer in excel for xp (2002).





    edit: Do I have to duplicate this post in the vba section too?
    Last edited by drgkt; 10-15-2016 at 05:14 AM.

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Hide, Switch to hidden

    Works was only finally deprecated in 2009 but the user interface had not been updated since the days of Windows 95... all in all a little later than 3.1, but a good lightweight app in any case.

    You should ask a Mod to move the thread.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,730

    Re: Hide, Switch to hidden

    "Microsoft works" was a "kind-of-office" package back in windows 3.1.
    Yes, I know - I go back a lot further than that!

    As Cytop has said, ask a mod to move the thread to the VBA section if that's the type of solution you are looking for.

  6. #6
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    I am actually looking for any solution that works.

    Should I take your posts as "You can only do this via vba"?

    Thanks

    @cytop: Thanks for putting the record straight!

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,730

    Re: Hide, Switch to hidden

    As far as I am aware, this is only possible using VBA.

  8. #8
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    ok then. Asked to be moved.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,730

    Re: Hide, Switch to hidden

    Deleted - no longer relevant.
    Last edited by AliGW; 10-15-2016 at 09:09 AM.

  10. #10
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Hide, Switch to hidden

    See if this can help

    Sub Hide_Unhide()
    r = InputBox("1  Hide Selected Rows" & Chr(13) & "2  Hide Selected Columns" & Chr(13) & "3  All Rows Vissible" & Chr(13) & "4  All Collums Visible" & Chr(13) & "5  All Vissible")
    With Selection
        If r = 1 Then .Rows.Hidden = True
        If r = 2 Then .Columns.Hidden = True
        If r = 3 Then ActiveSheet.Rows.Hidden = False
        If r = 4 Then ActiveSheet.Columns.Hidden = False
        If r = 5 Then ActiveSheet.Rows.Hidden = False: ActiveSheet.Columns.Hidden = False
    End With
    End Sub
    Kind regards
    Leo
    Attached Files Attached Files

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Hide, Switch to hidden

    This routine will hide all unselected cells. If a discontinuous range is selected, it will hide as many cells as excel allows.
    (e.g if you select the discontinuous range A1:C10, G12:R20, then it will be visible and G1:R10 will also be visible as will A12:C20.)

    Sub HideUnSelectedCells()
        Dim CellsLeft As Range, CellsRight As Range
        Dim CellsAbove As Range, CellsBelow As Range
        
        Dim RangeToSee As Range
        Dim AreaToSee As Range
        Dim rng As Range
        
        Set RangeToSee = Selection
        
        With RangeToSee
            Set AreaToSee = Range(.Areas(1), .Areas(.Areas.Count))
        End With
        
        With AreaToSee
            With .Parent.Cells
                .EntireColumn.Hidden = False
                .EntireRow.Hidden = False
            End With
            On Error Resume Next
                Range(.Parent.Cells(Rows.Count, Columns.Count), .Offset(.Rows.Count, 0).Cells(1, 1)).EntireRow.Hidden = True
                Range(.Parent.Cells(1, 1), .Cells(1, 1).Offset(-1, 0)).EntireRow.Hidden = True
                Range(.Parent.Cells(Rows.Count, Columns.Count), .Offset(0, .Columns.Count).Cells(1, 1)).EntireColumn.Hidden = True
                Range(.Parent.Cells(1, 1), .Cells(1, 1).Offset(0, -1)).EntireColumn.Hidden = True
            On Error GoTo 0
        End With
        
        For Each rng In AreaToSee.Columns
            rng.EntireColumn.Hidden = (Application.Intersect(rng.EntireColumn, RangeToSee) Is Nothing)
        Next rng
        For Each rng In AreaToSee.Rows
            rng.EntireRow.Hidden = (Application.Intersect(rng.EntireRow, RangeToSee) Is Nothing)
        Next rng
    End Sub
    
    Sub UnHideAll()
        With Cells
            .EntireColumn.Hidden = False
            .EntireRow.Hidden = False
        End With
    End Sub
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  12. #12
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    @mikerickson

    Could you please modify to hide all EXCEPT selected cell ROWS?
    thx



    EDIT: Never mind, all I have to do is to show hidden columns.

    BUT: How to switch views back and forth?
    Last edited by drgkt; 10-15-2016 at 11:04 AM.

  13. #13
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    @LeoTaxi

    Leo , I want to hide all EXCEPT the selected rows.
    Then toggle view to hidden / visible back and forth.

  14. #14
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    Clarification.

    What I mean "switch views back and forth" might be better understood by "Make the visible hidden and the hidden visible".

    (Good name for the macro!)

  15. #15
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Hide, Switch to hidden

    This should do what you want.

    This is a two step process
    1) Define which cells you want to be always visible. Select a range and run the sub ResetTogglingCells.

    2) That sub will make only those cells visible. To switch back and forth, run the sub ToggleVisiblity, which it will.

    3) If you want a different range of cells to be always visible, run the ResetTogglingCells routine again, after selecting the new always-visible range.

    Each sheet will have its own ReservedCells (the ones that are always visible). Toggling the visibility setting on one sheet won't change any other sheet.
    The ResetTogglingCells and ToggleCells will only act only on the active sheet.

    Put this code in a normal module.
    ' in normal module
    
    Sub ToggleVisiblity()
        With ThisWorkbook
            .OnlyReservedCellsVisible = Not (.OnlyReservedCellsVisible)
        End With
    End Sub
    
    Sub ResetTogglingCells()
        Set ThisWorkbook.ReservedCells = Selection
        ThisWorkbook.OnlyReservedCellsVisible = True
    End Sub
    and put this code in the ThisWorkbook code module

    ' in ThisWorkbook code module
    
    Dim pReservedCells As Collection
    
    Private Sub Workbook_Open()
        Dim Sh As Worksheet
        Set ReservedCells = New Collection
        For Each Sh In ThisWorkbook.Worksheets
            ReservedCells.Add Item:=Nothing, Key:=Sh.CodeName
        Next Sh
    End Sub
    
    Property Get ReservedCells(Optional Sh As Variant) As Range
        If pReservedCells Is Nothing Then Set pReservedCells = New Collection
        If IsMissing(Sh) Then Set Sh = ActiveSheet
        On Error GoTo MakeEntry
            Set ReservedCells = pReservedCells(Sh.CodeName)
        On Error GoTo 0
        Exit Property
    MakeEntry:
        pReservedCells.Add Item:=Nothing, Key:=Sh.CodeName
        Resume
    End Property
    
    Property Set ReservedCells(Optional Sh As Variant, inVal As Range)
        If pReservedCells Is Nothing Then Set pReservedCells = New Collection
        If IsMissing(Sh) Then
            If inVal Is Nothing Then
                Set Sh = ActiveSheet
            Else
                Set Sh = inVal.Parent
            End If
        End If
        On Error Resume Next
        pReservedCells.Remove Sh.CodeName
        pReservedCells.Add Item:=inVal, Key:=Sh.CodeName
        On Error GoTo 0
    End Property
    
    Property Get OnlyReservedCellsVisible(Optional Sh As Variant) As Boolean
        If IsMissing(Sh) Then Set Sh = ActiveSheet
        Dim ReservedArea As Range, SeenCells As Range
        On Error Resume Next
        With ReservedCells(Sh)
            Set ReservedArea = Range(.Areas(1), .Areas(.Areas.Count))
        End With
        On Error GoTo 0
        If ReservedArea Is Nothing Then
            OnlyReservedCellsVisible = False
        Else
            Set SeenCells = Sh.Cells.SpecialCells(xlCellTypeVisible)
            OnlyReservedCellsVisible = (Application.Intersect(SeenCells, ReservedArea).Address = SeenCells.Address)
        End If
    End Property
    
    Property Let OnlyReservedCellsVisible(Optional Sh As Variant, inVal As Boolean)
        Dim RangeToSee As Range, AreaToSee As Range, rng As Range
        If IsMissing(Sh) Then Set Sh = ActiveSheet
        Set RangeToSee = Me.ReservedCells(Sh)
        If RangeToSee Is Nothing Then inVal = False
        
        If inVal Then
            With RangeToSee
                Set AreaToSee = Range(.Areas(1), .Areas(.Areas.Count))
            End With
            
            With AreaToSee
                With .Parent.Cells
                    .EntireColumn.Hidden = False
                    .EntireRow.Hidden = False
                End With
                On Error Resume Next
                    Range(.Parent.Cells(Rows.Count, Columns.Count), .Offset(.Rows.Count, 0).Cells(1, 1)).EntireRow.Hidden = True
                    Range(.Parent.Cells(1, 1), .Cells(1, 1).Offset(-1, 0)).EntireRow.Hidden = True
                    Range(.Parent.Cells(Rows.Count, Columns.Count), .Offset(0, .Columns.Count).Cells(1, 1)).EntireColumn.Hidden = True
                    Range(.Parent.Cells(1, 1), .Cells(1, 1).Offset(0, -1)).EntireColumn.Hidden = True
                On Error GoTo 0
            End With
            
            For Each rng In AreaToSee.Columns
                rng.EntireColumn.Hidden = (Application.Intersect(rng.EntireColumn, RangeToSee) Is Nothing)
            Next rng
            For Each rng In AreaToSee.Rows
                rng.EntireRow.Hidden = (Application.Intersect(rng.EntireRow, RangeToSee) Is Nothing)
            Next rng
        Else
            With Sh.Cells
                .EntireColumn.Hidden = False
                .EntireRow.Hidden = False
            End With
        End If
    End Property

  16. #16
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    That is quite some work!

    Thanks, goes without saying.

    Isn't there a simpler approach?

    Consider A1:A20 filled 1-20.

    Select 2,4,6,8,10,12,14,16,18,20 format - row - hide.

    You are left with the odd rows 1-19 (plus all the blank ones below).

    Now run the macro --> the even 2-20 show (plus all the blank ones).

    Run it again --> odd rows 1-19 show (plus all the blank ones).

    and so on.

    A subroutine could be added, not to include the blank rows in the views.

  17. #17
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Hide, Switch to hidden

    The code that I wrote is for the environment "user designates a range. A routine (ToggleVisibility) switches between only those cells visible and all cells visible. The user hiding/undhiding with normal excel features does not change the designated range."

    It sounds like you are looking for a routine that toggles between "show all cells and return-to-previous-hidden status" where user hiding/showing cells does effect the previous hidden status.

    It sounds like the logic of this routine would be

    If any cells are hidden Then
    - remember which cells are hidden
    - show all cells
    Else
    - hide the remembered cells
    End
    Is that what you are looking for?
    How do you want the user changing sheets to effect this? Will changing to a different sheet wipe the memory of the last hidden cells?

  18. #18
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Hide, Switch to hidden

    This reminded me of CustomViews.
    I don't know where it is located in your version of Excel, but in Excel 2011 its under the View menu.

    I think that this will do as I mentioned in the previous post.

    Sub ToggleMyView()
        Dim AllVisible As Boolean
        AllVisible = (Cells.SpecialCells(xlCellTypeVisible).Address = Cells.Address)
        If AllVisible Then
            On Error Resume Next
            ThisWorkbook.CustomViews("myView").Show
            On Error GoTo 0
        Else
            ThisWorkbook.CustomViews.Add viewname:="myView"
            Cells.EntireColumn.Hidden = False
            Cells.EntireRow.Hidden = False
        End If
    End Sub

  19. #19
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Hide, Switch to hidden

    This macro only shows all rows...

    See sample workbook
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by drgkt; 10-15-2016 at 02:43 PM.

  20. #20
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Hide, Switch to hidden

    I opened your workbook.

    Manualy hid rows 2,4,6,8,10,12,14,16,18 and 20

    Ran ToggleViews, the result was that all rows were visible

    I ran ToggleViews again, the result was that Rows 2,4,6,8,10,12,14,16,18 and 20 were again hidden

    Ran ToggleViews, all rows were visible

    Ran ToggleViews again, Rows 2,4,6,8,10,12,14,16,18 and 20 were hidden

    Is this not what you wanted?

  21. #21
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    No! Please read post 16 again!

    Manualy hid rows 2,4,6,8,10,12,14,16,18 and 20 (So, you are left with the odds).

    Ran ToggleViews, the result was that all rows were visible. (Desired result: Show the ones you have hidden: even 2-20)

    I ran ToggleViews again, the result was that Rows 2,4,6,8,10,12,14,16,18 and 20 were again hidden. (Desired result: Show the odds 1-19)

    Ran ToggleViews, all rows were visible. (Desired result: Show the even)

    Ran ToggleViews again, Rows 2,4,6,8,10,12,14,16,18 and 20 were hidden. (Desired result: Show the odd)



    edit: I prefer to have this macro in the PERSONAL.XLS if I could.
    Last edited by drgkt; 10-15-2016 at 03:59 PM.

  22. #22
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Hide, Switch to hidden

    So its not "toggle between all and some" but "toggle between one group and another"


    How does one know which are to be omitted.

    In the example with 2,4,6,...20 as one group, you want 1,3,5,...,19 to be shown, but how does one know about 21, 22, 23 .....

    Is the first group "see 1,3,5,7,9,11,13,15,17,19,21,22 and all higher rows" and the other group "see only 2,4,6,8,10,12,14,16,18 and 20 and no other rows"?

  23. #23
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    Quote Originally Posted by mikerickson View Post
    So its not "toggle between all and some" but "toggle between one group and another"


    How does one know which are to be omitted.

    In the example with 2,4,6,...20 as one group, you want 1,3,5,...,19 to be shown, but how does one know about 21, 22, 23 .....

    Is the first group "see 1,3,5,7,9,11,13,15,17,19,21,22 and all higher rows" and the other group "see only 2,4,6,8,10,12,14,16,18 and 20 and no other rows"?
    "but how does one know about 21, 22, 23 ...." : Only 10 rows we manually hid and 21,22,23 (in fact nothing below 20 was hidden), so one view would be odd 1-19 plus 21,22,23... till the end of sheet, and the other view would be even 2-20 (just the ones you manually hid).

    "Is the first group "see 1,3,5,7,9,11,13,15,17,19,21,22 and all higher rows" and the other group "see only 2,4,6,8,10,12,14,16,18 and 20 and no other rows"?"
    Yes, that is it.

    Did not try your next post yet, I 'll let you know.
    Thanks!
    Last edited by drgkt; 10-16-2016 at 02:18 AM.

  24. #24
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Hide, Switch to hidden

    If you are dealing only with whole rows, this might work for you.
    Sub AntiView()
        Dim AllVisible As Boolean
        Dim VisibleRows As Range, oneRow As Range
        AllVisible = (Cells.SpecialCells(xlCellTypeVisible).Address = Cells.Address)
        If AllVisible Then
           Rem no hidden rows to reverse
           Beep
        Else
            Set VisibleRows = Cells.SpecialCells(xlCellTypeVisible).EntireRow
            Cells.EntireRow.Hidden = False
            For Each oneRow In VisibleRows.Areas
                oneRow.EntireRow.Hidden = True
            Next oneRow
        End If
    End Sub
    This is a modification that limits the action to the UsedRange
    Sub AntiView()
        Dim AllVisible As Boolean
        Dim VisibleRows As Range, oneRow As Range
        AllVisible = (Cells.SpecialCells(xlCellTypeVisible).Address = Cells.Address)
        If AllVisible Then
           Rem no hidden rows to reverse
           Beep
        Else
            Set oneRow = Range(Cells(1, 1), ActiveSheet.UsedRange)
            Set VisibleRows = Application.Intersect(Cells.SpecialCells(xlCellTypeVisible), oneRow).EntireRow
            Cells.EntireRow.Hidden = False
            For Each oneRow In VisibleRows.Areas
                oneRow.EntireRow.Hidden = True
            Next oneRow
        End If
    End Sub
    Last edited by mikerickson; 10-15-2016 at 07:10 PM.

  25. #25
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    Duplicate. Deleted.
    Last edited by drgkt; 10-16-2016 at 02:57 AM.

  26. #26
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Hide, Switch to hidden

    Bingo!

    The first code in post 23 is more proper (actually switching view between hidden - visible)

    BUT
    The second might come in handy too!

    Thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How do I hyperlink to a hidden tab, then hide that tab again.
    By sameclipse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-25-2015, 04:15 AM
  2. [SOLVED] Toggle Switch to hide/show column groups.
    By MLijoi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-22-2015, 02:57 PM
  3. [SOLVED] Hide Row if Rows are Hidden
    By reba0729 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-22-2013, 04:22 PM
  4. Hide a row if rows below it are hidden
    By reba0729 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2013, 09:19 AM
  5. [SOLVED] how 2 hide row if row in another sheet is hidden?
    By xz in forum Excel General
    Replies: 1
    Last Post: 02-26-2006, 02:25 PM
  6. [SOLVED] how can I hide a column and keep it hidden
    By Roy in forum Excel General
    Replies: 1
    Last Post: 01-12-2006, 11:20 AM
  7. [SOLVED] need a switch-How Do I Hide A Row (if a condition is true) using a Macro ?
    By Anthony Fantone in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-16-2005, 12:05 PM

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