Hiding rows issue

Jemmi

New Member
Joined
Jun 18, 2014
Messages
12
End goal:
To enter a numeric value in a cell, and according to the value, it will hide all rows based on different values in a set column.

Example:
Enter 4 in cell B2 and it will hide all rows which contain values "AB5, AB6, AB7, AB8" in column P.

What i've tried:
VBA code, but i can only get it to work through defining which rows I want to hide, which is a problem as I have over 16000 rows of data. I'd like it to work dynamically dependant on the value in column P:


Code:
[TABLE="width: 65"]
<tbody>[TR]
[TD]Sub worksheet_change(ByVal target As Range)[/TD]
[/TR]
[TR]
[TD]If Not Intersect(target, Range("B2")) Is Nothing Then[/TD]
[/TR]
[TR]
[TD]    ActiveSheet.Rows("10:20000").EntireRow.Hidden = False[/TD]
[/TR]
[TR]
[TD]    If target = 1 Then[/TD]
[/TR]
[TR]
[TD]        ActiveSheet.Rows("12:18").EntireRow.Hidden = True[/TD]
[/TR]
[TR]
[TD]    ElseIf target = 2 Then[/TD]
[/TR]
[TR]
[TD]        ActiveSheet.Rows("13:18").EntireRow.Hidden = True[/TD]
[/TR]
[TR]
[TD]    ElseIf target = 3 Then[/TD]
[/TR]
[TR]
[TD]        ActiveSheet.Rows("14:18").EntireRow.Hidden = True[/TD]
[/TR]
[TR]
[TD]    ElseIf target = 4 Then[/TD]
[/TR]
[TR]
[TD]        ActiveSheet.Rows("15:18").EntireRow.Hidden = True[/TD]
[/TR]
[TR]
[TD]    ElseIf target = 5 Then[/TD]
[/TR]
[TR]
[TD]        ActiveSheet.Rows("16:18").EntireRow.Hidden = True[/TD]
[/TR]
[TR]
[TD]    ElseIf target = 6 Then[/TD]
[/TR]
[TR]
[TD]        ActiveSheet.Rows("17:18").EntireRow.Hidden = True[/TD]
[/TR]
[TR]
[TD]    ElseIf target = 7 Then[/TD]
[/TR]
[TR]
[TD]    End If[/TD]
[/TR]
</tbody>[/TABLE]



Conditional formatting may be a solution I haven't looked into yet, but really i'd to be able to type in a number and I see the information I need, enabling me to copy this to another sheet/document. I'd really appreciate any pointers on the best way of doing this, thanks.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,256
Messages
6,123,915
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top