Filtering a table query

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,032
Office Version
  1. 365
Platform
  1. Windows
All, I have a table query named

Table_Query_from_SysproServer5

Where I'm pulling data out of Syspro, The header name in cell B2 is "JOB" I have a job number in Cell B1 that I would like to filter the table with. Right now I have filters on the table and can copy paste B1 into the filter on B2 and it does what I want. Normally I record those steps and save the macro add a button and then people use it.

Here is what I get but want what ever is in B2 as the criteria not 20222026 all the time
Sub Macro12
'
' Macro12 Macro
'

'
SQL:
    Range("B1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveSheet.ListObjects("Table_Query_from_SysproServer5").Range.AutoFilter _
        Field:=1, Criteria1:="20222026"
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Code:
Sub FilterTo()


Application.ScreenUpdating = False

If Sheets("YOUR SHEET NAME HERE").Range("B1").Value <> "" Then

'
    ActiveSheet.ListObjects("Table_Query_from_SysproServer5").Range.AutoFilter Field:=2, Criteria1:="*" & Sheets("YOUR SHEET NAME HERE").Range("B1").Value & "*", Operator:=xlAnd
    
    Else
    
    End If
    

Application.ScreenUpdating = True

End Sub

Try this. I tried to tweak something I use. You may have to play around with it. I changed these so that it would work for you. if it doesnt work then thats were you may have to test different things
Field:=2


The value I was searching for (filtering to) was in the first field

I have this code tied to a button on the sheet.
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,566
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top