Hi,
I really appreciate any help you can give me with regards to this issue.
I am attempting to use criteria, entered by the user, through a textbox I have implemented in a userform as the basis of the criteria for an autofilter. The code I have so far is below;
'' The value I want to enter into the textbox will be in the form of, =100, <=99, >90 and so on, and I want this to be the criteria for the autofilter. Although an error does not occur the code does not work effectively and the filter does not to do what I want it to do.Private Sub CancelButton_Click() Private Sub TextBox1_Change() x = TextBox1.Value End Sub Private Sub OKButton_Click() Application.ScreenUpdating = False If OptionHSDPA_SR Then Range("E3").Select Selection.AutoFilter Selection.AutoFilter Field:=5, Criteria1:="& x" , Operator:=xlAnd
''However, if I define x = "<=95" and change the line of code too, Selection.AutoFilter Field:=5, Criteria1:=x , Operator:=xlAnd, it works but I need to specify the operand in the textbox.
End If
Any help would be great.
Regards,
David
Last edited by kinseld5; 02-06-2012 at 06:32 AM.
welcome on the forum - first of all please read forum rules and use code tags
You wrote
so I think that excel expect second CriteriaSelection.AutoFilter Field:=5, Criteria1:="& x" , Operator:=xlAnd
Let say you have Autofilter in range("E3")
so you can organize data using following code
Private Sub OKButton_Click() Application.ScreenUpdating = False If OptionHSDPA_SR Then ActiveSheet.Range("E3").AutoFilter Field:=1, Criteria1:=textbox1.text 'or ' ActiveSheet.Range("E3").AutoFilter Field:=1, Criteria1:=textbox1.text, Operator:=xlAnd, Criteria2:=textbox2.text 'for use two criteria Application.ScreenUpdating = False End if End Sub
Best Regards
MaczaQ
---------------------------------------------------------------------------------------------------------------------------
If you are satisfied with the solution(s) provided, please mark your thread as Solved
If you are pleased with my answer consider to use the Scales iconto rate it - This way you will add me some reputation points ... thanks in advance.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks