Using VBA how to change the backend query definition of a table in Excel

Salman Shamim

New Member
Joined
Jun 15, 2017
Messages
4
Hello Dear All,

There is a table in excel 2016 made out of a SQL Query which is linked to a few pivot tables, each month we open the SQL query in Query Editor and change the parameters and save. Later we refresh all the pivot tables to update.

My Question is: Is there a way to change or update that SQL Query in VBA like inputting dates in a cell and pressing a button, where the parameter is updated and the table is refreshed.

We use excel 2016 and the database is SQL SERVER 2014.


Your assistance will be highly appreciated and will be a lifesaver.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You can use cells to feed the query

something rough I use

EMPLOYEEID = Sheets("driver hx").Range("a6").Value 'Cells(7, 1).Value
getuser = EMPLOYEEID

Var1 = Var1 & "where ( a.personnel = '" & getuser & "' ) " & vbCrLf
 
Upvote 0
I used to do that in Excel 2007 however with a query in place via excel 2016 query editor i am stumped on how to do it ? and even if i use the connection string methodology i need to update a certain table in the workbook so all associated pivot tables are refreshed.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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