Hi
I was wondering if someone could help me.
I need to add two more criteria (from date and to date) filter
the code: http://www.vbaexpress.com/kb/getarticle.php?kb_id=786
Thanks very much in advance
Hi
I was wondering if someone could help me.
I need to add two more criteria (from date and to date) filter
the code: http://www.vbaexpress.com/kb/getarticle.php?kb_id=786
Thanks very much in advance
Do you want all the filter criterion to be taken as an input via an input box or they are going to be value in some cell?
...via an input box.
try this in the user form now insert 3 textfields instead of one
CLICK the STAR icon on the left side below their user name to say thank you to those who had helped you. Thanks.![]()
Option Explicit Function FilterAndCopy(rng As Range, Choice1 As String, Choice2 as string, choice3 as string) Dim FiltRng As Range 'Clear Contents to show just new search data Worksheets("Sheet2").Cells.ClearContents 'Set the column to filter (In This Case 1 or A) 'Change as required rng.AutoFilter Field:=1, Criteria1:=Choice1 'Set the column to filter (In This Case 2 or B) 'Change as required rng.AutoFilter Field:=2, Criteria1:=Choice2 'Set the column to filter (In This Case 3 or c) 'Change as required rng.AutoFilter Field:=1, Criteria1:=Choice3 On Error Resume Next Set FiltRng = rng.SpecialCells(xlCellTypeVisible).EntireRow On Error Goto 0 'Copy Data across to sheet 2 FiltRng.Copy Worksheets("Sheet2").Range("A1") 'Display Data Worksheets("Sheet2").Select Range("A1").Select Set FiltRng = Nothing End Function Sub formshow() 'Show Search Form UserForm1.Show End Sub '***************************************************************** 'In a userform Option Explicit Private Sub CommandButton1_Click() Dim rng As Range 'Set Error Handling On Error Goto ws_exit: Application.EnableEvents = False 'Set Range Set rng = ActiveSheet.UsedRange 'Cancel if no value entered in textbox If TextBox1.Value = "" or TextBox2.Value = "" or TextBox3.Value = "" Then Goto ws_exit: 'Call function Filterandcopy FilterAndCopy rng, TextBox1.Value, TextBox2.Value, TextBox3.Value rng.AutoFilter 'Exit sub ws_exit: Set rng = Nothing Application.EnableEvents = True Unload Me End Sub Private Sub CommandButton2_Click() 'Cancel Button Unload Me End Sub
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
Select Thread Tools-> Mark thread as Solved.
To undo, select Thread Tools-> Mark thread as Unsolved.
thank you very much
but, It's possible that....
Textbox1 = text (abc) = Column A
TextBox2 = date from (1.10.12) = Column B
Textbox3 = date to (4.10.12) = Column B
result:
textBox1 and (TextBox2 (up) to textbox3) => Sheet 2
Thanks very much
Pl. use this codeCLICK the STAR icon on the left side below their user name to say thank you to those who had helped you. Thanks.![]()
Option Explicit Function FilterAndCopy(rng As Range, Choice1 As String, Choice2 as string, choice3 as string) Dim FiltRng As Range 'Clear Contents to show just new search data Worksheets("Sheet2").Cells.ClearContents 'Set the column to filter (In This Case 1 or A) 'Change as required rng.AutoFilter Field:=1, Criteria1:=Choice1 'Set the column to filter (In This Case 2 or B) 'Change as required rng.AutoFilter Field:=2, Criteria1:= _ ">=" & choice2, Operator:=xlAnd, Criteria2:="<=" & c On Error Resume Next Set FiltRng = rng.SpecialCells(xlCellTypeVisible).EntireRow On Error Goto 0 'Copy Data across to sheet 2 FiltRng.Copy Worksheets("Sheet2").Range("A1") 'Display Data Worksheets("Sheet2").Select Range("A1").Select Set FiltRng = Nothing End Function Sub formshow() 'Show Search Form UserForm1.Show End Sub '***************************************************************** 'In a userform Option Explicit Private Sub CommandButton1_Click() Dim rng As Range 'Set Error Handling On Error Goto ws_exit: Application.EnableEvents = False 'Set Range Set rng = ActiveSheet.UsedRange 'Cancel if no value entered in textbox If TextBox1.Value = "" or TextBox2.Value = "" or TextBox3.Value = "" Then Goto ws_exit: 'Call function Filterandcopy FilterAndCopy rng, TextBox1.Value, TextBox2.Value, TextBox3.Value rng.AutoFilter 'Exit sub ws_exit: Set rng = Nothing Application.EnableEvents = True Unload Me End Sub Private Sub CommandButton2_Click() 'Cancel Button Unload Me End Sub
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
Select Thread Tools-> Mark thread as Solved.
To undo, select Thread Tools-> Mark thread as Unsolved.
thank you very much
Last edited by dixiV; 10-04-2012 at 01:37 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks