Hi there.
I have a very simple macro that copies data from one worksheet to the other. This macro worked fine in Excel 2007. I have since migrated to to 2013. The newly arisen problem is that when I run the macro, the data is not copied to the 'Previous Part Data' worksheet. However, if I step through the code line by line, it works fine.
Here is the code:
Sheets("Current Part Data").Select 'Select the 'Current Part Data' worksheet
'Copy the data to the 'Previous Part Data' worksheet then clear the data
Range("A4:V" & CurrentPartDataFinalRow).Copy
Sheets("Previous Part Data").(Range("A4").PasteSpecial Paste:=xlValues
Range("A4:V" & CurrentPartDataFinalRow).ClearContents
Again, run on its own, it does not paste the data into "Previous Part Data', but stepping through line by line works just fine. I need to only paste the values which is why I did not use 'copy destination: xxx'. I found that if I select the worksheet before pasting, then the code works fine as seen below:
Sheets("Current Part Data").Select 'Select the 'Current Part Data' worksheet
'Copy the data to the 'Previous Part Data' worksheet then clear the data
Range("A4:V" & CurrentPartDataFinalRow).Copy
Sheets("Previous Part Data").Select 'Select the 'Previous Part Data' worksheet
Range("A4").PasteSpecial Paste:=xlValues
Sheets("Current Part Data").Select 'Select the 'Current Part Data' worksheet
Range("A4:V" & CurrentPartDataFinalRow).ClearContents
Display More
I have two questions:
1. Why did this work in 2007 and not in 2013?
2. Is there something I can do to get rid of the sheet selection statements to avoid cluttering my code?
Cheers,
JJ