Kiwi-123
asked on
VB filter
Is there a way to set the filter in column J to "Top 10" via a command button
I was hoping to set the filter in B by:-
Private Sub CommandButton1_Click()
ActiveSheet.[B1].Select
Sheets("Archive").Unprotec t Sheets("DataSheet").Range( "B3").Valu e
Dim wks As Worksheet
Dim currentFiltRange As String
Dim cDateCriteria() As Variant
Dim i As Long
Dim r As Range
Dim rng As Range
Set wks = ThisWorkbook.Sheets("Archi ve")
If wks.FilterMode Then wks.ShowAllData
wks.Range("$C$9:$C$60000") .AutoFilte r Field:=2, _
Criteria1:=">=" & Format(wks.Range("C2").Val ue, "mm/dd/yyyy"), _
Operator:=xlAnd, _
Criteria2:="<" & Format(wks.Range("C3").Val ue + 1, "mm/dd/yyyy")
Sheets("Archive").Protect Sheets("DataSheet").Range( "B3").Valu e, AllowFiltering:=True
End Sub
Then at the end of the code I would add the filter by top 10 in coumn J
help19.xls
I was hoping to set the filter in B by:-
Private Sub CommandButton1_Click()
ActiveSheet.[B1].Select
Sheets("Archive").Unprotec
Dim wks As Worksheet
Dim currentFiltRange As String
Dim cDateCriteria() As Variant
Dim i As Long
Dim r As Range
Dim rng As Range
Set wks = ThisWorkbook.Sheets("Archi
If wks.FilterMode Then wks.ShowAllData
wks.Range("$C$9:$C$60000")
Criteria1:=">=" & Format(wks.Range("C2").Val
Operator:=xlAnd, _
Criteria2:="<" & Format(wks.Range("C3").Val
Sheets("Archive").Protect Sheets("DataSheet").Range(
End Sub
Then at the end of the code I would add the filter by top 10 in coumn J
help19.xls
ASKER
The function should already exist on the filter bar, I was just looking for the vb to make this a command click.
So I can already list the top 10 manually, but was looking for a lazy way to set the autofilter
So I can already list the top 10 manually, but was looking for a lazy way to set the autofilter
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks sbaughan, would you be able to help me integrate this into the existing code?
Sorry, I didn't see your post.
I'll try something tomorrow if you didnt't already make it.
Tell us how it goes!
I'll try something tomorrow if you didnt't already make it.
Tell us how it goes!
... been looking for the solution you ask and it seems that you'll need a workaround like this one ... or somebody esle has a better idea?
You can hide the column K if it bothers you