Generate next sequence number in excel

shahdelsol

Active Member
Joined
Jul 21, 2009
Messages
276
Office Version
  1. 365
Platform
  1. Windows
I am looking for macro that create next sequence number. Let's say I have 100 in A1. When I open the workbook , then I want B1 = 1 + whatever is in A1 in this case the result will be 101. Now I would want A1 becomes 101 as well. I close the file and reopen and now B1 is 102. I hope this make sense. Anyone can help? Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Put this in the ThisWorkbook module
VBA Code:
Sub Workbook_open()
[b1] = [a1] + 1
[a1] = [b1]
End Sub
 
Upvote 0
Put this in the ThisWorkbook module
VBA Code:
Sub Workbook_open()
[b1] = [a1] + 1
[a1] = [b1]
End Sub
This works but the problem is now you have to save workbook in order to get next sequence number and I don't want to save workbook. Is there a way around? Basically when I open workbook I want B1 with next number which is 1 + previous number. 100 doesn't have to be in A1 as long as there is way to keep track of the number each time I open workbook. Does this make sense?
 
Upvote 0
workbook changes won't be maintained If you don't save the workbook !
 
Upvote 0
workbook changes won't be maintained If you don't save the workbook !

workbook changes won't be maintained If you don't save the workbook !
Understood. My workbook will be read-only file that's why I wouldn't be able to save it unless we would create another code to take it out of read-only file , save changes and then make it read-only again. Is this do-able ?
 
Upvote 0
But read only can be turned on / off by the user anyway !
AND you will still have to save the workbook
 
Upvote 0
But read only can be turned on / off by the user anyway !
AND you will still have to save the workbook
Understood but it doesn't work for me. I have found something that uses notepad for sequence number which does the job but I thought I could something without using notepad. Thanks for help
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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