MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Increment the vaule (number) in a cell based upon a condition

Posted by Tim G on June 01, 2001 12:00 PM

I am trying to create a customized invoice template and I've run into a roadblock. I can't seem to write a macro that will increment the value in my "Invoice #" cell. I want the value to increment each time I press a form button, so I need to assign a macro to the button. I understand how to assign the macro, I just can't write one that will function correctly in both the template version AND the workbook version.

Posted by Joe Was on June 01, 2001 12:48 PM

Have a starting value in your "Invoice #" cell. Note the cell address. On the Macro page name your macro, I used "Increase_B8" B8 being the cell that has the invoice #.
Copy & paste, [B8].Value = [B8] + 1
If you have macros already Edit any one and add all the code below with copy & paste. Change the cell address and title. Close macros.

Build button, View-Toolbars-Forms select button, place on sheet assign your macro.

This will increase the invoice # by one each time the button is clicked. JSW

Sub Increase_B8()
[B8].Value = [B8] + 1
End Sub

Posted by Tim G on June 01, 2001 10:38 PM

Thank You

Thanks Joe,
This is a big help! Next semester I'm taking some Visual Basic classes; I can see that they will be of great help. Thanks again.