VBA to automatically change cell number

KAYE04

New Member
Joined
Mar 14, 2019
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Hi I have this excel file and i create a macro that every time i will click the button (next invoice) the data will clear contents and cell J7 will change to the next number

for example when i click next invoice Cell J7 will turn to CS-0002, then CS-0003, CS-0004 and specific ranges will clear.

here are my codes

Sub NextInvoice()

Worksheets("Table 1").Range("b10:b55").ClearContents
Worksheets("Table 1").Range("d10:e55").ClearContents
Worksheets("Table 1").Range("d6:d7").ClearContents
Worksheets("Table 1").Range("h6:h6").ClearContents
Worksheets("Table 1").Range("j6:j6").ClearContents

End Sub

thank you in advance
 
VBA Code:
Sub NextInvoice()

Worksheets("Table 1").Range("b10:b55").ClearContents
Worksheets("Table 1").Range("d10:e55").ClearContents
Worksheets("Table 1").Range("d6:d7").ClearContents
Worksheets("Table 1").Range("h6:h6").ClearContents
Worksheets("Table 1").Range("j6:j6").ClearContents
Worksheets("Table 1").Range("J7").Value = Worksheets("Table 1").Range("J7").Value + 1

End Sub

Enter 'CS-0000' or CS-0001' as the starting number in cell J7.
 
Upvote 0
Solution
VBA Code:
Sub NextInvoice()

Worksheets("Table 1").Range("b10:b55").ClearContents
Worksheets("Table 1").Range("d10:e55").ClearContents
Worksheets("Table 1").Range("d6:d7").ClearContents
Worksheets("Table 1").Range("h6:h6").ClearContents
Worksheets("Table 1").Range("j6:j6").ClearContents
Worksheets("Table 1").Range("J7").Value = Worksheets("Table 1").Range("J7").Value + 1

End Sub

Enter 'CS-0000' or CS-0001' as the starting number in cell J7.
Thank you this helpss
 
Upvote 0

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