Advancing A Number With The Push A Button

M

Minitman

Greeting,

I have an invoice that uses a button to advance the invoice number by
1. When I wrote it the numbers were just numbers, but since then a
letter has been added to the front of the number (was 17445 now
D-017445). My advancing code no longer works and I don't know why!

Here is the code:

Private Sub GetNextInv_Click()
Range("InvNoLast").Value = Range("InvNoLast").Value + 1
End Sub

Anyone have an idea on how to fix it?

Any help would be most appreciated.

TIA

-Minitman
 
F

Frank Kabel

Hi
one idea:
why not format the cell with the custom format:
"D-"000000

This way you still store the numbers but show the characters
 
J

Jerry W. Lewis

It no loger works because D-017445 is text, not a string. Addition with
strings is not defined.

Try

Private Sub GetNextInv_Click()
Dim x As String
x = Range("A1").Value
Range("A1").Value = Left(x, 2) & Application.Text(CDbl(Mid(x, _
3, Len(x) - 2)) + 1, "000000")
End Sub

Jerry
 
M

Minitman

Thank you Frank and Jerry,

One other problem, how would I modify this code to use a ScrollBar?

-Minitman
 
M

Minitman

No. But I have never used one and wanted to get a little experience
with them.
 
Top