Macro Stops for no apparent reason

Brendan63

New Member
Joined
Nov 7, 2017
Messages
8
Hi, our system generates reports as CSV files. I have a macro in a spreadsheet to open these, copy them and paste them into this sheet, (it then goes on and does other stuff.)

The macro just stops after opening the first CSV file, but if i step through, it works fine.

It even works right to the end if I step through to the copy line then run the macro.


Workbooks.Open Filename:= _ "C:\Reports\ Report1_Oct-2017.CSV"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Windows("Reports.xlsm").Activate
Sheets("CSV Report 1").Select
ActiveSheet.Paste
Range("A4").Select
Workbooks.Open Filename:= _
"C:\Reports\ Report2_Oct-2017.CSV"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Reports.xlsm").Activate
Sheets("CSV 2").Select
ActiveSheet.Paste
Range("A4").Select
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi, our system generates reports as CSV files. I have a macro in a spreadsheet to open these, copy them and paste them into this sheet, (it then goes on and does other stuff.)

The macro just stops after opening the first CSV file, but if i step through, it works fine.

It even works right to the end if I step through to the copy line then run the macro.


Workbooks.Open Filename:= _ "C:\Reports\ Report1_Oct-2017.CSV"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Windows("Reports.xlsm").Activate
Sheets("CSV Report 1").Select
ActiveSheet.Paste
Range("A4").Select
Workbooks.Open Filename:= _
"C:\Reports\ Report2_Oct-2017.CSV"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Reports.xlsm").Activate
Sheets("CSV 2").Select
ActiveSheet.Paste
Range("A4").Select
The first thing I'd suggest is to check for consistency in your file naming. It would appear that you have a potential typo, see the red highlights.

How many reports would this macro have to handle? And then, would you have to edit this macro for to prepare reports for next month?
If so, report back on the above comment and advise if you need assistance to follow up on my second query.
 
Upvote 0
How about
Code:
Workbooks.Open Filename:="C:\Reports\ Report1_Oct-2017.CSV"
ActiveSheet.UsedRange.Copy
Windows("Reports.xlsm").Sheets("CSV Report 1").Paste
Range("A4").Select
Workbooks.Open Filename:= _
"C:\Reports\ Report2_Oct-2017.CSV"
ActiveSheet.UsedRange.Copy
Windows("Reports.xlsm").Sheets("CSV 2").Paste
Range("A4").Select
 
Upvote 0
How do you run the macro initially - anything involving the Shift key?
 
Last edited:
Upvote 0
Hi Brian, the red highlighted are the tab names, which are correct, although I probably should rename to make it less messy. There are 4 reports in all, but the macro stops after opening the first.
I do a Ctrl H each month to change the months.
 
Upvote 0
How about
Code:
Workbooks.Open Filename:="C:\Reports\ Report1_Oct-2017.CSV"
ActiveSheet.UsedRange.Copy
Windows("Reports.xlsm").Sheets("CSV Report 1").Paste
Range("A4").Select
Workbooks.Open Filename:= _
"C:\Reports\ Report2_Oct-2017.CSV"
ActiveSheet.UsedRange.Copy
Windows("Reports.xlsm").Sheets("CSV 2").Paste
Range("A4").Select
Thanks Fluff, but no difference, although the line "ActiveSheet.UsedRange.Copy" is much better than my 3 lines.
 
Upvote 0
Try using a key combo that doesn’t involve Shift and see if that fixes it.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top