Macro stopping unexpectedely

alainfranco

New Member
Joined
Mar 7, 2012
Messages
38
Greetings,

I am going bald. Bald from all the hair I've been pulling off trying to fix an issue I apparently do not understand, caused by a problem I didn't know was one before this occurred. Please help.

And now with the context: My workbook was built on Excel 2013 on Windows 7. I use this file to log billable services and then to generate invoices, leveraging stand alone Client Billing Templates, sitting in the same folder as the Registry. All Client Billing Template have a tab called "Template" which is identical from one file to another, with the exception of Client specific information such as addresses and etc....

This tab is copied, pasted in the same file, and data is then copied from the Registry file, into it. Saved and exported to PDF. Simple enough, and worked like a charm until I dropped my laptop, which was later pronounced dead, and ultimately replaced by a new one running Excel 2016, on Windows 10, if that matters at all.

While most of the workbook works as designed on my new laptop, there are a few macros that no longer work, and I have spent countless hours trying to figure it out, using my limited knowledge of VBA.

What happens is that the macro works fine, until it hits a precise point in the script, and then unexpectedly stops, for no apparent reason. Again, always at the same place, judging from what I can see when I run the macro using F8.

Here is an excerpt of the code:

Code:
Sub WeeklyInvoicing()


    Application.ScreenUpdating = False
    
    ' Set environment parameters and variables
      
    BillableClient = ThisWorkbook.ActiveSheet.Cells(1, 17).Value
    BillingDay = ThisWorkbook.ActiveSheet.Cells(4, 1).Value
    PathOfFile = "C:\Users\xxx\MyDocs\BillingTemplates\"
    NameOfFile = BillableClient
    ExtentionOfFile = ".xlsm"


    'Create an Invoice Worksheet in the Client Billing Template
    
    Workbooks.Open Filename:=PathOfFile & NameOfFile & ExtentionOfFile
    
    Sheets("Template").Select
    Sheets("Template").Copy After:=Worksheets(Worksheets.Count)

[U][B]THIS IS THE PRECISE SPOT WHERE THE MACRO STOPS, FOR NO APPARENT REASON
[/B][/U]

    
......... Rest of the Macro which does what I described above.

The line that seems to be causing it is :

Sheets("Template").Copy After:=Worksheets(Worksheets.Count)

Does any one know why this is happening and how I can fix it?

Eternal recognition for the person who can help....!

Many thanks,


****** id="cke_pastebin" style="position: absolute; top: 600.8px; width: 1px; height: 1px; overflow: hidden; left: -1000px;"> Sheets("Template").Copy After:=Worksheets(Worksheets.Count)
</body>
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Code:
Sheets("Template").Copy After:=Worksheets(Worksheets.Count)
and
Code:
[LEFT][COLOR=#222222][FONT=Verdana]Sheets("Template").Copy After:=sheets(sheets.Count)[/FONT][/COLOR][/LEFT]
work in my file (without selecting the sheet) even if the sheet is hidden.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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