I have a workbook with a main sheet and several data sheets. Each data sheet has a single parameterized query that returns data for a business. I have the queries setup so they all use the same parameter, and the parameter value is taken from a cell on the main sheet. By changing this parameter cell, all the queries recalculate and return data for the business I'm interested in. This works fine manually.
Now I want to run a macro and that creates a "report" for each business. I run the macro recorder and carefully record cutting and pasting the name of each business into the parameter cell and and saving the results in a new workbook.
When I play the mactro,
the cutting and pasting and saving all takes place ok, but none of the queries "fire". Each "report" has the same data (for the last business) instead of the actual correct individual business data.
I have the parameters for my queries set to "Get the Value from the following cell", and then have specified the cell and also have checked to "Refresh automatically when the cell value changes".
When the macro cut and pastes into the parameter cell, the queries don't run except for the very last cut and paste.
Here is an extract from the macro:
Range("I6").Select
Selection.Copy
Range("I2").Select
ActiveSheet.Paste
Sheets("Main Sheet").Select
Application.CutCopyMode = False
Sheets("Main Sheet").Copy
ChDir "C:Business"
ActiveWorkbook.SaveAs Filename:= _
"C:BusinessBus1.xls", _
FileFormat:=xlNormal, Password:="",
WriteResPassword:="",
_ReadOnlyRecommended:=False,
CreateBackup:=False
ActiveWindow.Close
Range("I7").Select
Selection.Copy
Range("I2").Select
ActiveSheet.Paste
Sheets("Main Sheet").Select
Application.CutCopyMode = False
Sheets("Main Sheet").Copy
ActiveWorkbook.SaveAs Filename:= _
"C:BusinessBus2.xls", _
FileFormat:=xlNormal,
Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
Range("I8").Select
Selection.Copy
Range("I2").Select
ActiveSheet.Paste
Sheets("Main Sheet").Select
Application.CutCopyMode = False
Sheets("Main Sheet").Copy
ActiveWorkbook.SaveAs Filename:= _
"C:BusinessBus3.xls", _
FileFormat:=xlNormal,
Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
It only seems to activate the queries for the last cut and paste. How do I get the macro to run the queries on the other cut and pastes? Is there a different pattern I can use instead of cut and paste? Thanks
p.s. I'm using Excel 2000 (9.0.3821 SR-1).
Now I want to run a macro and that creates a "report" for each business. I run the macro recorder and carefully record cutting and pasting the name of each business into the parameter cell and and saving the results in a new workbook.
When I play the mactro,
the cutting and pasting and saving all takes place ok, but none of the queries "fire". Each "report" has the same data (for the last business) instead of the actual correct individual business data.
I have the parameters for my queries set to "Get the Value from the following cell", and then have specified the cell and also have checked to "Refresh automatically when the cell value changes".
When the macro cut and pastes into the parameter cell, the queries don't run except for the very last cut and paste.
Here is an extract from the macro:
Range("I6").Select
Selection.Copy
Range("I2").Select
ActiveSheet.Paste
Sheets("Main Sheet").Select
Application.CutCopyMode = False
Sheets("Main Sheet").Copy
ChDir "C:Business"
ActiveWorkbook.SaveAs Filename:= _
"C:BusinessBus1.xls", _
FileFormat:=xlNormal, Password:="",
WriteResPassword:="",
_ReadOnlyRecommended:=False,
CreateBackup:=False
ActiveWindow.Close
Range("I7").Select
Selection.Copy
Range("I2").Select
ActiveSheet.Paste
Sheets("Main Sheet").Select
Application.CutCopyMode = False
Sheets("Main Sheet").Copy
ActiveWorkbook.SaveAs Filename:= _
"C:BusinessBus2.xls", _
FileFormat:=xlNormal,
Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
Range("I8").Select
Selection.Copy
Range("I2").Select
ActiveSheet.Paste
Sheets("Main Sheet").Select
Application.CutCopyMode = False
Sheets("Main Sheet").Copy
ActiveWorkbook.SaveAs Filename:= _
"C:BusinessBus3.xls", _
FileFormat:=xlNormal,
Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
It only seems to activate the queries for the last cut and paste. How do I get the macro to run the queries on the other cut and pastes? Is there a different pattern I can use instead of cut and paste? Thanks
p.s. I'm using Excel 2000 (9.0.3821 SR-1).