Hide Rows based of items from a ComboBox List.

Glitch_

New Member
Joined
Oct 15, 2014
Messages
4
I have 2 Combo box's sitting side by side, based off the list I need rows hidden and shown, so that the proper questions are shown. This is repeated down the sheet.

This is the code I was using when I was using Data Validation, however since I need the arrow on the right hand side to always show I switched to Combo box's.

Any help would be greatly appreciated.

Thank you in advance for any help.
Code:
 Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range, x As Long, y As Long
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    If Not Application.Intersect(Target, Range("B20,E20,B27,E27,B34,E34,B41,E41,B48,E48")) Is Nothing Then
        x = Target.Offset(1).Row: y = Target.Offset(6).Row
        For Each Cell In Range(Range("B" & x), Range("B" & y))
            Cell.EntireRow.Hidden = (Left(Range("B" & Cell.Row), 1) = " " And Left(Range("E" & Cell.Row), 1) = " ")
        Next
    End If
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    If Not Application.Intersect(Target, Range("B62,E62,B66,E66,B69,E69,B70,E70,B74,E74")) Is Nothing Then
        x = Target.Offset(1).Row: y = Target.Offset(3).Row
        For Each Cell In Range(Range("B" & x), Range("B" & y))
            Cell.EntireRow.Hidden = (Left(Range("B" & Cell.Row), 1) = " " And Left(Range("E" & Cell.Row), 1) = " ")
        Next
    End If
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub

Ok here is the code for what I currently have but Combox.1 cancels out Combobox.2 I cannot figure out how to put these two together.
Code:
Private Sub ComboBox1_Change()
 If ComboBox1.Value = "Awning" Then
        ActiveSheet.Range("21:25").EntireRow.Hidden = False
    ElseIf ComboBox1.Value = "Parallelagrams" Then
        ActiveSheet.Range("21:22").EntireRow.Hidden = False
        ActiveSheet.Range("23:25").EntireRow.Hidden = True
    ElseIf ComboBox1.Value = "Marketing_Case" Then
        ActiveSheet.Range("21:22").EntireRow.Hidden = False
        ActiveSheet.Range("23:25").EntireRow.Hidden = True
    ElseIf ComboBox1.Value = "New_Item" Then
        ActiveSheet.Range("21:25").EntireRow.Hidden = True
    End If
End Sub


Private Sub ComboBox2_Change()
    If ComboBox2.Value = "Awning" Then
        ActiveSheet.Range("21:25").EntireRow.Hidden = False
    ElseIf ComboBox2.Value = "Parallelagrams" Then
        ActiveSheet.Range("21:22").EntireRow.Hidden = False
        ActiveSheet.Range("23:25").EntireRow.Hidden = True
    ElseIf ComboBox2.Value = "Marketing_Case" Then
        ActiveSheet.Range("21:22").EntireRow.Hidden = False
        ActiveSheet.Range("23:25").EntireRow.Hidden = True
    ElseIf ComboBox2.Value = "New_Item" Then
        ActiveSheet.Range("21:25").EntireRow.Hidden = True
    End If
End Sub

I have asked this question on another site as well as I really need answers.
Hide Rows based of items from a ComboBox List.
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Found the solution my using a series of true or false functions to decide weather the list box is true and then using the if function to create a number based of what the selection is. looks like this.
[TABLE="width: 384"]
<tbody>[TR]
[TD]Awning[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: right"]1[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]Parallelagrams[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: right"]4[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: right"]4[/TD]
[/TR]
[TR]
[TD]Marketing_Case[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: right"]4[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: right"]4[/TD]
[/TR]
[TR]
[TD]Select[/TD]
[TD="align: center"]TRUE[/TD]
[TD="align: right"]4[/TD]
[TD="align: center"]FALSE[/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]


Then put this in sheet one.

Code:
 Private Sub ComboBox1_Change()    If Range("M20").Value = "4" Then
        Rows("21:25").EntireRow.Hidden = True
    ElseIf Range("M20").Value = "1" Then
        Rows("21:25").EntireRow.Hidden = False
ElseIf Range("M20").Value = "2" Then
    Rows("21:22").EntireRow.Hidden = False
    Rows("23:25").EntireRow.Hidden = True
ElseIf Range("M20").Value = "3" Then
    Rows("21:22").EntireRow.Hidden = False
    Rows("23:25").EntireRow.Hidden = True
   End If
End Sub
Private Sub ComboBox2_Change()
    If Range("M20").Value = "4" Then
        Rows("21:25").EntireRow.Hidden = True
    ElseIf Range("M20").Value = "1" Then
        Rows("21:25").EntireRow.Hidden = False
ElseIf Range("M20").Value = "2" Then
    Rows("21:22").EntireRow.Hidden = False
    Rows("23:25").EntireRow.Hidden = True
ElseIf Range("M20").Value = "3" Then
    Rows("21:22").EntireRow.Hidden = False
    Rows("23:25").EntireRow.Hidden = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,705
Members
453,748
Latest member
akhtarf3

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