Tearing My Hair Out

CordeliaEarle

New Member
Joined
Jun 19, 2019
Messages
7
Hope someone can tell me what I am doing wrong.

I have copied and pasted from this web page: https://www.mrexcel.com/news/next-invoice-number/

and have corrected all the cell numbers to do with my saving details, and the macro is perfect. BUT, when I then go in to the invoices again, to invoice some more at the end of the next month I always get the following error:
36vRandbvJwPbDV5YoJPpW
36vRandbvJwPbDV5YoJPpW
https://picmonkey.space/invite/36vRandbvJwPbDV5YoJPpW

Please tell me why this happens.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
36vRandbvJwPbDV5YoJPpW
Right this is the coding, apparently my picture won't share!!!

Sub NextInvoice()
Range("E4").Value = Range("E4").Value + 1
Range("B14:D34").ClearContents
End Sub


Sub SaveInvWithNewName()
Dim NewFNAsVariant
'CopyInvoicetoanewworkbook
ActiveSheet.Copy
NewFN = "D:\PetSitting\Invoices" & Range("E4").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice


The red line is the one that comes up in the debug
 
Upvote 0
Hi & welcome to MrExcel
What error number & message do you get?
 
Upvote 0
Should the file be called Invoices1.xlsx, or should it be 1.xlsx, in a folder called Invoices
 
Upvote 0
The file should call itself Invoices1.xslx, which it does perfectly when I set up the Macro and then saves consecutively. Then the next month when I go to enter the next lot of invoices I use the macro enabled template and it then starts doing this. Is it because I am opening the template and not the last invoice? I really hope I'm making sense.

Cx
 
Upvote 0
Try
Code:
Sub SaveInvWithNewName()
   Dim NewFN As String
   'CopyInvoicetoanewworkbook
   ActiveSheet.Copy
   NewFN = "D:\PetSitting\Invoices" & Range("E4").Value & ".xlsx"
   ActiveWorkbook.SaveAs NewFN, 51
   ActiveWorkbook.Close
   NextInvoice
End Sub
But if E4 reverts back to 1 at the start of each month, you'll have a problem as the file already exists.
 
Upvote 0
hi Fluff,

No the file doesn't revert back.

So as I've been tearing my hair out, lol, I've been manually saving and adding the next invoice number. If I put this code in to the template file, when I have closed program, shut down, stopped the world etc, which file do I open again to start the next time? The template or the xls file?

Do I just start again with a new template file and start with my next invoice number will that work, rather than trying to re-code the bugged one?

Cx
 
Upvote 0
If the template is an .xlsm file, then just keep using that.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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