Incrementing Alphanumeric Invoice Number

D

Domenic

Hi,

I'm currently using the following macro to increment the invoice number
for my invoice template:

Counter1 = Range("H8").Value
Counter1 = Counter1 + 1
Range("H8").Value = Counter1

I'd like to change the numbering for these invoices so that they begin
with two letters, for example, AA0001, AA0002, etc.

How can the above code be modified so that it would increment the
alphanumeric invoice number accordingly?

Thanks!
 
J

JE McGimpsey

Domenic said:
I'm currently using the following macro to increment the invoice number
for my invoice template:

Counter1 = Range("H8").Value
Counter1 = Counter1 + 1
Range("H8").Value = Counter1

I'd like to change the numbering for these invoices so that they begin
with two letters, for example, AA0001, AA0002, etc.

How can the above code be modified so that it would increment the
alphanumeric invoice number accordingly?

One way:

Assuming that only AA0000 to AA9999 are valid (i.e, the prefix doesn't
increment):

Dim sCounter As String
Dim nCounter As Long
sCounter = Range("H8").Value
nCounter = Mid(sCounter, 3) + 1
If nCounter < 10000 Then
Mid(sCounter, 3) = Format(nCounter, "0000")
Else
sCounter = "Number out of range"
End If
Range("H8").Value = sCounter
 
D

Domenic

Hi JE,

Thank you sooooo much for your help! I had wondered if it was possible,
since the invoice number included alpha characters. Thankfully, I see
it is. That's great!

Thanks again for your help!
 
B

Bob Greenblatt

Hi,

I'm currently using the following macro to increment the invoice number
for my invoice template:

Counter1 = Range("H8").Value
Counter1 = Counter1 + 1
Range("H8").Value = Counter1

I'd like to change the numbering for these invoices so that they begin
with two letters, for example, AA0001, AA0002, etc.

How can the above code be modified so that it would increment the
alphanumeric invoice number accordingly?

Thanks!
Or, you can format cell H8 as "AA"00000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top