AndrewSomiah
New Member
- Joined
- Mar 23, 2015
- Messages
- 4
Hello Excel Experts,
Could anyone help me with a Marco that I am trying to write. Basically my challenge is to write a Marco that automatically generates an invoice using the next sequence of numbers I have. I also want a Marco to save the last version of the invoice while generating a new one with the next number in sequence while clearing the data from the old worksheet.
I have managed to write the code thus far but when i run the marco which is assigned to a button I get a runtime error "13" type mismatch. I cannot spot the error in my code can anyone assis. Below is what i am trying to get working in my .xlsm file.
The debug is flaggin the error I have highlighted in red. I am not sure what i am doing wrong?
Cell C7 is where my invoice number is stored. Cell range A18:D21 is my data which is calculating cost. I hope I have given enough infpormation to help debug this code.
Sub NextInvoice()
Range("C7").Value = Range("C7").Value + 1
Range("A18:D21").ClearContents
End Sub
Sub SaveInvWithNewName()
Dim NewFN As Variant
'Copy invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\Users\Somiah\Documents\Invoice\Inv" & Range("C7").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
End Sub
Could anyone help me with a Marco that I am trying to write. Basically my challenge is to write a Marco that automatically generates an invoice using the next sequence of numbers I have. I also want a Marco to save the last version of the invoice while generating a new one with the next number in sequence while clearing the data from the old worksheet.
I have managed to write the code thus far but when i run the marco which is assigned to a button I get a runtime error "13" type mismatch. I cannot spot the error in my code can anyone assis. Below is what i am trying to get working in my .xlsm file.
The debug is flaggin the error I have highlighted in red. I am not sure what i am doing wrong?
Cell C7 is where my invoice number is stored. Cell range A18:D21 is my data which is calculating cost. I hope I have given enough infpormation to help debug this code.
Sub NextInvoice()
Range("C7").Value = Range("C7").Value + 1
Range("A18:D21").ClearContents
End Sub
Sub SaveInvWithNewName()
Dim NewFN As Variant
'Copy invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\Users\Somiah\Documents\Invoice\Inv" & Range("C7").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
End Sub
Last edited: