Updating query criteria using VBA

laniganb320

New Member
Joined
Jan 30, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
We have 100+ customers that we are including in a report; we have to run a query for each customer, and they each have their own criteria that will be used.

I’m trying to create a macro that will:
  • Update the criteria used in the query to Like "*Customer 1*"
  • Run the query for the first customer
  • Update the criteria to Like "*Customer 2*"
  • Run the query again
  • Update the criteria to Like "*Customer 3*"
  • Etc.
What would the VBA look like to accomplish this?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I would do this.
In a table have the customer ID and possibly a boolean field to indicate customer should be included in the report run.
Create a recordset from that table where boolean field is true.
Loop through the recordset using the customer id for each record and build the criteria, then run the query.

HTH
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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