How to hide/show cells depending on selection from drop down box?

swhitesides

New Member
Joined
Apr 17, 2009
Messages
16
I want to display a selection in a drop down box (1-15). If "1" is chosen then rows 11, 27, & 43 should be displayed. If "2" is chosen then rows 11-12, 27-28, & 43-44 should be displayed. If "3" is chosen then rows 11-13, 27-29, & 43-45 should be displayed. If "4" is chosen then rows 11-14, 27-30, & 43-46 should be displayed. All the way to if "15" is chosen then rows 11-25, 27-41 & 43-57 is displayed. I thnk it would be a macro, I'm just not sure how to make this work. Any suggestions would be greatly appreciated!
 

SteveO59L

Well-known Member
Joined
Apr 21, 2004
Messages
7,896
Assuming your data validation cell is D1.

Try something along the lines of

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 And Target.Column = 4 Then
If Target.Value = 1 Then
Rows("12:26").Hidden = True
Rows("28:42").Hidden = True
Rows("44:100").Hidden = True
Else
Rows("12:100").Hidden = False

End If
End If
 

jbeaucaire

Well-known Member
Joined
May 8, 2002
Messages
6,012
Let's assume the data validation cell is D1.
Right-click the sheetname and select VIEW CODE, paste in this sheet-level macro:
Rich (BB code):
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
    If Not Intersect(Target, Range("D1")) Is Nothing Then
        Range("A11:A57").EntireRow.Hidden = True
        r = Target.Value - 1
        Range("A11:A" & 11 + r).EntireRow.Hidden = False
        Range("A27:A" & 27 + r).EntireRow.Hidden = False
        Range("A43:A" & 43 + r).EntireRow.Hidden = False
    End If
End Sub
Or this, shorter, but harder to read:
Rich (BB code):
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
    If Not Intersect(Target, Range("D1")) Is Nothing Then
        Range("A11:A57").EntireRow.Hidden = True
        r = Target.Value - 1
        Range("A11:A" & 11 + r & ",A27:A" & 27 + r & ",A43:A" & 43 + r).EntireRow.Hidden = False
    End If
End Sub
The close the VBEditor and save your sheet. Now any change to D1 should change the visible rows.
 

Forum statistics

Threads
1,082,284
Messages
5,364,282
Members
400,787
Latest member
bs04c

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top