Use Same Query With Different Where Clause RRS feed

  • Question

  • I need to run the same query but with a diff where clause for each worksheet.  For examples sake, let's say 4 worksheets that the queries would be

    Sheet1 = Select * from sales where salesman = 'Bob'

    Sheet2 = Select * from sales where salesman = 'Mark'

    Sheet3 = Select * from sales where salesman = 'Joe'

    Sheet4 = Select * from sales where salesman = 'Kevin'

    Is there a possible way for me to use ONE connection for all of my queries and just change the where clause from sheet to sheet as opposed to having to import the query every time for each worksheet in the workbook?

    Wednesday, May 11, 2016 7:40 PM


  • You could create a query with a where clause that changes based on a value in an Excel cell. However, you won't be able to create a single query that uses different where clauses depending on the sheet it's being filled to.

    Your best bet will likely be to turn your query into a function, and pass the filter value to the function from each of your four queries.

    Some more info on turning a regular query into a function:


    Thursday, May 12, 2016 6:54 PM