Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27336

Combox reset

$
0
0
I have a long list in excel and use two comboboxes to hide rows based on the value in certain cells (by column grp and column sdpi). These comboboxes both also have an 'All' option so the view can be reset back to showing everything.

What I want to do is tweak this code so that if combobox1 is changed then combobox2 is changed, combobox1 resets back to 'All' before hiding the values.

I'm not sure if that makes sense... I thought about adding Combobox.Value = "All" in there somewhere, but it seems to set to 'All' and stop there and not make the selection in the combobox that the user asks for.

Code:

Private Sub ComboBox1_Change()
Application.ScreenUpdating = False
Dim sdpi As String
sdpi = ComboBox1.Value
    If sdpi = "All" Then
    For Each cell In Range("E3:E65536")
        If cell.Value <> "" Then
            cell.EntireRow.Hidden = False
        End If
    Next
    Else
    For Each cell In Range("E3:E65536")
      If cell.Value <> "" Then
        If cell.Value <> sdpi Then
        cell.EntireRow.Hidden = True
        Else
        cell.EntireRow.Hidden = False
        End If
      End If
    Next
    End If
Application.ScreenUpdating = True
End Sub
Private Sub ComboBox2_Change()
Application.ScreenUpdating = False
Dim grp As String
grp = ComboBox2.Value
    If grp = "All" Then
    For Each cell In Range("D3:D65536")
        If cell.Value <> "" Then
            cell.EntireRow.Hidden = False
        End If
    Next
    Else
    For Each cell In Range("D3:D65536")
      If cell.Value <> "" Then
        If cell.Value <> grp Then
        cell.EntireRow.Hidden = True
        Else
        cell.EntireRow.Hidden = False
        End If
      End If
    Next
    End If
Application.ScreenUpdating = True
End Sub


Viewing all articles
Browse latest Browse all 27336

Trending Articles