I have an SQL query which I need to run dedicated to each employee.
Each employee is to have their own sheet on the workbook. I have created the VBA script which queries our database, pulls a list of employees, lists them on the first sheet in E1:E(x), then creates all the sheets based on that list. Now the task is to run a query for each employee and have the results in each sheet. Essentially:
Employees: AA, AB, AC, AD, AE
Variable = AA
For each employee,
Run query with Variable
Insert query results
Increment Variable
Repeat until end of Employees.
I've Googled it from every angle I can think of, but I can't find a solution. I'm drawing a blank. I've tried
just as a test, but this results in the value being put only in the last employee sheet. It doesn't iterate through the rest of the employees. If I use Worksheets("First sheet").Select in the middle, the results are only on the "First sheet".
If I can insert a value into each sheet, I can just replace the inserting of the value with the query and iterate through that, replacing the employee variable to match the sheet.
Can anyone help?
Bookmarks