I'm trying to write a macro that copies one sheet in my workbook (master) and pastes it to all other sheets in the workbook (excluding master). Fairly certain I need a loop but I'm not 100%.
I'm trying to write a macro that copies one sheet in my workbook (master) and pastes it to all other sheets in the workbook (excluding master). Fairly certain I need a loop but I'm not 100%.
egArtikPlease Login or Register to view this content.
If all the sheets are empty and you just want values.
Please Login or Register to view this content.
This works. However, my master file contains a query. When I run this macro, I create a duplicate query (master (2)). Anyway to delete this second query but keep the formatting of the table (which is lost if pasting as values)?
Alternativity, I have altered the code to paste values and then past formats to keep source formatting. I'd like to clear the sheet before pasting, so I inserted the following:
However, I'm now getting an error at:Please Login or Register to view this content.
Please Login or Register to view this content.
There are some bugs here.
You are trying to select cell A1 in the worksheet (wks) under examination. Even if it is successful with one sheet, it will definitely cause an error in the next one. To select a cell on any worksheet, it must be active. The code does not show that you activate the sheet under test.Please Login or Register to view this content.
But there is no need to activate the worksheet and select a cell to do the following:
For example, you can:Please Login or Register to view this content.
No activation, no selection, and rows are deleted.Please Login or Register to view this content.
And we come to the problem of the error in the line:Before the For Each ... Next loop, you are copying the range rng, but by executing a line that removes rows, the copy mode is canceled. And that's why you get an error.Please Login or Register to view this content.
You will need in this loop to copy and paste the scope of the source into the worksheet you are examining.
Artik
That fixed it
Thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks