Hello all,
I have data in an existing excel workbook that I am trying to copy into a new workbook and then rename the new file based on given variable names.
I had previously recorded macros to autofilter the data, select the range of cells I wanted to copy, create a new workbook and past the data into sheet 1 of the new workbook. I linked these different macros to buttons in the original workbook. The macros/buttons all work fine.
However, I was asked to combine all of the macros into one step and place a single button on the main sheet. Here is where things go wrong. If I try to copy the code from each macro into one subroutine, the code crashes when the following piece of code executes: Range("XX:YY").Select, which is to select the data I want to copy. I get this error, Run-time error '1004': Application-defined or object-defined error.
If I simply tell the new subroutine to just run each macro in order like this(simplified for example):
Application.Run Macro1
Application.Run Macro2
Application.Run Macro3
Each macro executes fine with no errors. I guess I don't want all these extra macros in the file and want to simplify things. Am I missing something with the range selection? Should I be using a different selection function like Cells?
Any help would be greatly appreciated. I didn't post all of the code because it seems like the issue is with the cell/range selection. And before it is asked, yes I declared all the necessary variables.
I have data in an existing excel workbook that I am trying to copy into a new workbook and then rename the new file based on given variable names.
I had previously recorded macros to autofilter the data, select the range of cells I wanted to copy, create a new workbook and past the data into sheet 1 of the new workbook. I linked these different macros to buttons in the original workbook. The macros/buttons all work fine.
However, I was asked to combine all of the macros into one step and place a single button on the main sheet. Here is where things go wrong. If I try to copy the code from each macro into one subroutine, the code crashes when the following piece of code executes: Range("XX:YY").Select, which is to select the data I want to copy. I get this error, Run-time error '1004': Application-defined or object-defined error.
If I simply tell the new subroutine to just run each macro in order like this(simplified for example):
Application.Run Macro1
Application.Run Macro2
Application.Run Macro3
Each macro executes fine with no errors. I guess I don't want all these extra macros in the file and want to simplify things. Am I missing something with the range selection? Should I be using a different selection function like Cells?
Any help would be greatly appreciated. I didn't post all of the code because it seems like the issue is with the cell/range selection. And before it is asked, yes I declared all the necessary variables.