G
Guest
Hi there I have this following code at the moment,
Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")
rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value
If cnt > 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub
It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.
But I am having all sorts of trouble getting it to work.
Regards
Private Sub Combobox1_Click()
Dim sh As Worksheet, rng As Range
Dim cnt As Long
If ComboBox1.ListIndex = -1 Then
MsgBox "Select a name first, then select a month"
Exit Sub
End If
Set sh = ActiveSheet
If sh.AutoFilterMode = True Then
If sh.FilterMode Then _
sh.ShowAllData
sh.AutoFilterMode = False
End If
Set rng = sh.Range(sh.Cells(1, 2), _
sh.Cells(1, 2).End(xlDown))
cnt = Evaluate("sumproduct(--(" & rng.Address & "=""" & _
ComboBox1.Value & """),--(" & rng.Offset(0, 1).Address & _
"=""" & cmbName & """))")
rng.Resize(, 3).AutoFilter Field:=1, Criteria1:=ComboBox1.Value
If cnt > 0 Then
rng.Resize(, 3).AutoFilter Field:=2, Criteria1:=cmbName.Value
Else
rng.Resize(, 3).AutoFilter Field:=3, Criteria1:=cmbName.Value
End If
End Sub
It is running off a user form that lets them select their name from a
dropdown list and then the month they wish to look at. The month is situated
in Column B and the Names are situated in Columns C & D. I want it to first
filter the month and then filter the names colum C & D (as their name may
appear in both columns) and then show the results on the screen. If they
don't have any information for that month then I want a pop up to say "No
risks for this month........" and just show the risks relating to their name.
But I am having all sorts of trouble getting it to work.
Regards