unhide rows based on value of particular cell?

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,056
Office Version
  1. 365
Platform
  1. Windows
how can i unhide a range of cells dependent upon the value of a particular cell above? so, if cell C16 is between 11 and 20, unhide rows 50-60, if between 21 and 30, unhide 50 - 70, etc etc
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
denis,

trying to modify this one for something else and am curious. Can the target values be alphas instead of numerics? My need this time stems from users picking their name out of a drop down list and once selected, all other sections/rows will be hidden. So, the Intersect(Target, Range("f172") will contain a drop down list of operator names eg Qld Rail, Bribie, Brisbane Transport, BCC Ferries, Buslink, Caboolture, ...etc

On selecting "Qld Rail" all the other sections will remain hidden. is there a way to say:

"Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("f172")) Is Nothing Then Exit Sub
Rows("187:2786").RowHeight = 0
Select Case Target.Value

Case "Qld Rail"
.Rows("187:339").AutoFit
etc etc etc"

ajm
 
Upvote 0
Denis,

any clue why this one doesn't do the job?
first tried it as a Sub () and then as a Worksheet Change - neither seems to work?

F172 has a list of operators in a drop down box, when its changed to a particular operator, we only want that operator's rows below it to be displayed.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Sht As Worksheet
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("f172")) Is Nothing Then Exit Sub
Set Sht = Sheets("Parameters and Assumptions")
With Sht
.Rows("187:2786").RowHeight = 0
ElseIf Target = "QRail" Then
.Rows("187:339").AutoFit
ElseIf Target = "Bribie" Then
.Rows("340:492").AutoFit
ElseIf Target = "BrisbaneTransport" Then
.Rows("493:645").AutoFit
ElseIf Target = "BCCFerries" Then
.Rows("646:798").AutoFit
ElseIf Target = "Buslink" Then
.Rows("799:951").AutoFit
ElseIf Target = "Caboolture" Then
.Rows("952:1104").AutoFit
ElseIf Target = "Clarks" Then
.Rows("1105:1257").AutoFit
ElseIf Target = "Hornibrook" Then
.Rows("1258:1410").AutoFit
ElseIf Target = "Kangaroo" Then
.Rows("1411:1563").AutoFit
ElseIf Target = "MtGravatt" Then
.Rows("1564:1716").AutoFit
ElseIf Target = "National" Then
.Rows("1717:1869").AutoFit
ElseIf Target = "ParkRidge" Then
.Rows("1870:2022").AutoFit
ElseIf Target = "Sunbus" Then
.Rows("2023:2175").AutoFit
ElseIf Target = "Thompson" Then
.Rows("2176:2328").AutoFit
ElseIf Target = "Westside" Then
.Rows("2329:2481").AutoFit
ElseIf Target = "SouthernCross" Then
.Rows("2482:2634").AutoFit
ElseIf Target = "Surfside" Then
.Rows("2635:2787").AutoFit
ElseIf Target = "AllOPerators" Then
.Rows("187:2940").AutoFit
End If
End Sub
 
Upvote 0
denis, stress not. got it running with some help from Jindon. cheers big ears.
 
Upvote 0
Hi Andrew,

Glad you got it sorted. Just got aroiund to seeing the code -- you needed Select Case instead of all the ElseIf statements.

Denis
 
Upvote 0
ajm
I'd rather reply here to your question in the other thread

I would do like this and assuming the code is in "Parameters and Assumptions" sheet module
Code:
Option Compare Text

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRows As String
If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Range("f172")) Is Nothing Then Exit Sub
With Me
   .Rows("187:2786").RowHeight = 0
   Select Case Target.Value
      Case "QRail" : myRows = "187:339"
      Case "Bribie" : myRows = "340:492"
      Case "BrisbaneTransport" : "493:645"
      Case "BCCFerries" : "646:798" 
      Case "Buslink" : myRows = "799:951"
      Case "Caboolture" : myRows = "952:1104"
      Case "Clarks" : myRows = "1105:1257"
      Case "Hornibrook" : myRows = "1258:1410"
      Case "Kangaroo" : myRows = "1411:1563"
      Case "MtGravatt" : myRows = "1564:1716"
      Case "National" : myRows = "1717:1869"
      Case "ParkRidge" : myRows = "1870:2022"
      Case "Sunbus" : myRows = "2023:2175"
      Case "Thompson" : myRows = "2176:2328"
      Case "Westside" : myRows = "2329:2481"
      Case "SouthernCross" : "2482:2634"
      Case "Surfside" : myRows = "2635:2787"
      Case "AllOPerators" : myRows = "187:2940"
   End Select
   If Len(myRows) Then .Rows(myRows).AutoFit
End With
End Sub
 
Upvote 0
thanks jindon. "Case "QRail": myRows = "187:339"" is where the proble lies. all other rows appear as selected. any ideas on this?
 
Upvote 0
Possibly the word "QRail" in the list contains extra space, so try

Select Case Trim(Target.Value)
 
Upvote 0
good point. I had QldRail instead of QRail. **** decaffeinated coffee must have been put in the regular coffee jar again....

many thanks.
 
Upvote 0

Forum statistics

Threads
1,224,885
Messages
6,181,588
Members
453,055
Latest member
cope7895

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