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
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
Last edited by Rocky2013; 11-07-2013 at 10:09 PM.
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.
Regards![]()
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
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] .
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,
Last edited by Rocky2013; 10-27-2013 at 07:57 AM.
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
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.
Hi Rocky2013,
Sorry, I did not check that, and I was out for most of the day.
Please try the attached sample Workbook.
Regards
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?
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
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
Thanks all. They all workd.
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.
Hello Rocky2013,
Just cange that line to:
If this has solved your problem, then please mark this Thread as Solved.![]()
If Target.Rows.Count > 1 Then Exit Sub
You may also Click on the Star to the far left, at the bottom of this Post, to Add Reputation.
Regards
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.
Hello Rocky2013,
You are welcome.
Glad that it now works for you. Thank you also for having marked this thread as "Solved".
Regards
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.
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!![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks