Hello,
The segment of code below is giving me fits.
The macro is written to automatically open an existing spreadsheet, copy some cells and paste the data into the spreadsheet where the macro resides.
When I open the spreadsheet and run the macro, it runs exactly as I need without any issues.
However, if I run it a second time, the copying and pasting is all messed up. It seems to distribute the copied data across several additional columns, acting almost as a Text to Columns function.
I have to close out of Excel entirely to get it to run properly again. No issues with the first run, but subsequent runs I have problems.
[codebox]
Columns(“A:D”).Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWindow.Close
Columns(“A:D”).Select
ActiveSheet.Paste[/codebox]
I tried modifications to the code to where it only selects and copies the data that is there:
[codebox] Range(“A1:D1”).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.copy
[/codebox]
I’ve also tried copying rows instead of columns.
And I have also selected in the target sheet just the range of A1.
I’ve set the display alerts back to “true” after closing, and I do get an alert about the size not matching. I suspect this might have something to do with it, but so far I’ve not been able to pinpoint exactly where the problem is.
The spreadsheets I am copying from are in .xls format and the spreadsheet where I am pasting is a .xlsm spreadsheet.
I am using Excel 2007.
Thanks in advance for the advice!