Hello,
I'm new to excel vba and have been trying to write a code for filtering a worksheet based on exact match to my criteria range. For example, column L on my sheet1 includes D2-D26 and I only need to filter D2 and D20. But with the code I currently have I get all cells that start with D2 such as D24 and D26. I have already tried ="=text" solution and it returns no values in my example. Here is what I have so far. I want the code to return exact match of values in R1:S19 and not approximate. Very much appreciate any suggestions you can provide.
Private Sub CommandButton1_Click()
Sheet1.Activate
Sheet1.Range("A1:N1").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1:N1").PasteSpecial
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("F:F").EntireColumn.AutoFit
Columns("G:G").EntireColumn.AutoFit
Columns("H:H").EntireColumn.AutoFit
Columns("I:I").EntireColumn.AutoFit
Columns("J:J").EntireColumn.AutoFit
Columns("K:K").EntireColumn.AutoFit
Columns("L:L").EntireColumn.AutoFit
Columns("M:M").EntireColumn.AutoFit
Columns("N:N").EntireColumn.AutoFit
Range("r4").Select
Sheets("Sort").Select
Application.CutCopyMode = False
Sheet1.Range("A3").Select
Sheets("Sheet2").Select
Sheets("Sort").Range("A1:N100000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets("Sort").Range("R1:S19"), CopyToRange:=Sheets("Sheet2").Range("A1:N1"), Unique:=False
I'm new to excel vba and have been trying to write a code for filtering a worksheet based on exact match to my criteria range. For example, column L on my sheet1 includes D2-D26 and I only need to filter D2 and D20. But with the code I currently have I get all cells that start with D2 such as D24 and D26. I have already tried ="=text" solution and it returns no values in my example. Here is what I have so far. I want the code to return exact match of values in R1:S19 and not approximate. Very much appreciate any suggestions you can provide.
Private Sub CommandButton1_Click()
Sheet1.Activate
Sheet1.Range("A1:N1").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1:N1").PasteSpecial
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("F:F").EntireColumn.AutoFit
Columns("G:G").EntireColumn.AutoFit
Columns("H:H").EntireColumn.AutoFit
Columns("I:I").EntireColumn.AutoFit
Columns("J:J").EntireColumn.AutoFit
Columns("K:K").EntireColumn.AutoFit
Columns("L:L").EntireColumn.AutoFit
Columns("M:M").EntireColumn.AutoFit
Columns("N:N").EntireColumn.AutoFit
Range("r4").Select
Sheets("Sort").Select
Application.CutCopyMode = False
Sheet1.Range("A3").Select
Sheets("Sheet2").Select
Sheets("Sort").Range("A1:N100000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets("Sort").Range("R1:S19"), CopyToRange:=Sheets("Sheet2").Range("A1:N1"), Unique:=False