+ Reply to Thread
Results 1 to 16 of 16

Click "-" or "+" to hide and unhide rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Click "-" or "+" to hide and unhide rows

    Hi,
    I received the help, it works if "+" or "-" in cloumn. I move the list lower and move one column it does not work any more.
    Attached is the code.

    Please advise.


    Thanks
    Attached Files Attached Files
    Last edited by Rocky2013; 11-07-2013 at 10:09 PM.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Click "-" or "+" to hide and unhide rows

    Hello Rocky2013,

    Moving the List lower, will not effect the Code. However, if you move it Right, say one Column, you have to change the Column Number in the Code as well.i.e;

    The Code below has been changed to work after moving the Data-set one Column to the Right.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column > 3 Then Exit Sub  ' Changed the original No.2 (Column B) to 3 (Column C) 
    If Target.Count > 2 Then Exit Sub
    If (Target <> "-") * (Target <> "+") Then Exit Sub
    Dim i As Long: Application.EnableEvents = False
    With Target.CurrentRegion.Columns(1)
        With .SpecialCells(2)
            For i = 1 To .Areas.Count
                If .Areas.Item(i).Address = Target.Address Then Exit For
            Next
        End With
        .SpecialCells(4).Areas.Item(i).EntireRow.Hidden = Target = "-"
    End With
    Application.EnableEvents = True
    Target.Value = IIf(Target = "+", "-", "+")
    End Sub
    Regards
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Click "-" or "+" to hide and unhide rows

    Hi,
    Thanks for the reply. I change the number it does not hide the rows properly, it hides the previous row(s).
    I need to the hide the rows below "-". Before "2" and "3" works the same way. I try to change
    the numbers on ....... If Target.Column > 3, Target.Count > 2, CurrentRegion.Columns(1), SpecialCells (2),
    SpecialCells (4); I could not make it work.

    I do not understandd what those codes means and how those work except Target.Column > 2 = means the
    column for "-" (I think).

    Can you please expain what those means and how those affect the hidden rows.

    Regards,
    Attached Files Attached Files
    Last edited by Rocky2013; 10-27-2013 at 07:57 AM.

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Click "-" or "+" to hide and unhide rows

    Hi Rocky,
    try it
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 2 Then Exit Sub
    If (Target <> "-") * (Target <> "+") Then Exit Sub
    Dim i As Long: Application.EnableEvents = False
    On Error Resume Next
    With Range("B12:C" & Cells(Rows.Count, 3).End(xlUp).Row).Columns(1)
        With .SpecialCells(2)
            For i = 1 To .Areas.Count
                If .Areas(i).Address = Target.Address Then Exit For
            Next
        End With
        .SpecialCells(4).Areas(i).EntireRow.Hidden = Target = "-"
    End With
    Application.EnableEvents = True
    Target.Value = IIf(Target = "+", "-", "+")
    End Sub

  5. #5
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Click "-" or "+" to hide and unhide rows

    Hi,
    It works, except in column B, there is not always has a sub-list. So in your attachment, I remove the "-"
    in column B, from row 26 (Shoes) to row 32 (Others). What happen when I click "-" in cell B22, rows from 23
    to 32 are hidden (except row 33 for some reason).

    I Click "+" in B22, hidden rows 23-32 would not unhide. I like when I click "-" in B22 (Drinks), only row 23 - 25
    are hidden. All other rows from row 26 to the end of remain shown, unless there is another "-" below row 22
    somewhere because my document has mixing with "+ or -" and without any sign (single line of data).
    So I assume the code would check "column B if the "+" or "-" are existed or not.

    Please advise

    Thanks of your help.


    Regards,
    Last edited by Rocky2013; 10-27-2013 at 09:51 AM.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Click "-" or "+" to hide and unhide rows

    Hi Rocky2013,

    Sorry, I did not check that, and I was out for most of the day.

    Please try the attached sample Workbook.

    Regards
    Attached Files Attached Files

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Click "-" or "+" to hide and unhide rows

    Hi Rocky,
    My code is focused on the +/- in a column B. So if you delete +/-, then the code will not work correctly.
    I recommend leaving +/- signs in single rows (Shoes ... Others). Whether it is suitable for you?

  8. #8
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Click "-" or "+" to hide and unhide rows

    Hi Winon,
    Your codes work except when I click "-" Drinks, rows from 21 to 30 are hidden. I like to only hide row 21-23
    (red texts), the other rows from 24-30 should remain no change in hide and unhide.

    I play around by adding an empty row after the "Apple Juice" before the "Shoes, it stops the rows for "Shoes"
    to "Others" from showing hide or unhide. Since my data has no empty row, so I get around is to change the
    height of the row to very minimal, to simulate an empty rows do not exist. If you have a solution to not having
    an empty to stop hide and unhide other data, I like to have that solution otherwise I will consider it is resolved.
    Please advise. I will wait for your reply before I change the post to "RESOLVE". Thanks

    Hi nilem,
    I take your advise. For those rows without the sub-data, I change the font color
    to white, so that "+" or "-" will not show. Thanks.

    Thanks a lot of your help to make this possible.

    Regards,

    Rocky2013

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Click "-" or "+" to hide and unhide rows

    Hello Rocky2013,

    Each Category must have the controlling "+" or "-" in the Column to the Left of each Category, otherwise the program regards it as the "Items" belonging to the last Category with the "+" or "-" in the cell on the left.

    I have done that for you in the attached sample Workbook. If no Items are listed below any Category, of course, nothing will be hidden or displayed.

    Hope that clears up the logic of the program for you.

    Regards
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Click "-" or "+" to hide and unhide rows

    Thanks all. They all workd.

  11. #11
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Click "-" or "+" to hide and unhide rows

    Hi Winon,
    I found there is a pop-up error meeage when I click the upper left corner to select all (left of column A and above row 1.
    It indicates "Run-time error '6': Overflow". I click deburg, "If Target.Count > 1 Then" at the top is highlighted in yellow.

    "How can I fix this, please advise.

    Thanks
    Last edited by Rocky2013; 11-06-2013 at 11:42 PM.

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Click "-" or "+" to hide and unhide rows

    Hello Rocky2013,

    Just cange that line to:

    If Target.Rows.Count > 1 Then Exit Sub
    If this has solved your problem, then please mark this Thread as Solved.

    You may also Click on the Star to the far left, at the bottom of this Post, to Add Reputation.

    Regards

  13. #13
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Click "-" or "+" to hide and unhide rows

    Hi Winon,
    It works now. Some day I have to find out what this code means to learn VBA.

    I click star - add repution. Do not know what happen after I click.
    Last edited by Rocky2013; 11-07-2013 at 10:12 PM.

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Click "-" or "+" to hide and unhide rows

    Hello Rocky2013,

    You are welcome.

    Glad that it now works for you. Thank you also for having marked this thread as "Solved".

    Regards

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Click "-" or "+" to hide and unhide rows

    Hello Rocky2013,

    I found another problem when selecting more than one Column. Maybe you would like the attached sample Workbook better?

    Also when you click on "+" or "-", I have made it that the "Activecell" moves one Cell to the left, so that one does not have to first go to another Cell and then back again to hide or unhide any selections.

    Just a thought.

    Regards.
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    2010
    Posts
    496

    Re: Click "-" or "+" to hide and unhide rows

    Hi Winon,
    This code works better. I know the previous code I need to go to another cell
    and back in order to hide and unhide, but I did not ask too much from you.

    I am greate you take another look.

    Thanks again!

+ 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 to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  2. Replies: 1
    Last Post: 09-21-2013, 03:18 AM
  3. [SOLVED] Disable "Right Click" ... or any ability to "cut", "insert", etc.
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2011, 09:26 AM
  4. [SOLVED] If &amp;quot;x&amp;quot; Hide / Unhide Rows
    By Ed in forum Excel General
    Replies: 4
    Last Post: 04-18-2006, 01:45 PM
  5. Replies: 8
    Last Post: 01-04-2006, 12:10 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