New invoice using macro

KAYE04

New Member
Joined
Mar 14, 2019
Messages
21
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have created a form in excel with invoice number which is alpha numeric.
im having a hard time fixing the error about the leading zeros in my invoice number. My invoice number is FIN19-0001.
i want to change it from FIN19-0001 to FIN19-0002, FIN19-0003 and so on.
but every time i click the button intended for that macro it will become FIN19-2. the 3 zeros are not included.
how can i fix it. can somebody help me.
thank you so much in advance.
\here is my code
Sub NextInvoice()
Range("B7").Value = Left(Range("B7").Value, 6) & 1 + Mid(Range("B7").Value, 7, 4)
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi,

enter the next numeric value (excluding the prefix) in your Range eg 2

then run this code

Code:
  Sub NextInvoice()
     With Range("B7")
        .Value = .Value + 1
        .NumberFormat = """FIN19-""0000"
    End With
End Sub

and see if this does what you want

Dave
 
Last edited:
Upvote 0
Sub NextInvoice()

Range("B7").Value = Left(Range("B7").Value, 6) & 1 + Mid(Range("B7").Value, 7, 4)
Range("D11:I11").ClearContents
Range("D12").ClearContents
Range("B26:I26").ClearContents
Range("B27:I27").ClearContents
Range("B28:I28").ClearContents
Range("B29:I29").ClearContents
Range("B30:I30").ClearContents
Range("B31:I31").ClearContents
Range("B32:I32").ClearContents
End Sub


Heres my code.
where exactly i will put the codes you are referring to.
im really sorry im just a newbie in macro

thank you so much
 
Upvote 0
Hi,
you replace your existing code my updated version.

Code:
Sub NextInvoice()
    With Range("B7")
        .Value = .Value + 1
        .NumberFormat = """FIN19-""0000"
    End With
    Range("D11:I11,D12,B26:I32").ClearContents
End Sub

If you have placed code in a standard module, and as the range is unqualified (you have not specified a worksheet) then your invoice sheet must be the active sheet when code is run.

Dave
 
Upvote 0
Run time error. type mismatch
i followed your instruction but it doesnt work.
i already copied your codes
:(
 
Upvote 0
did you first just enter a NUMERIC value only in the range without the Prefix as I stated in my first post?

Dave
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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