auto incremental numbers

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
741
Office Version
  1. 365
Platform
  1. Windows
hello all

can you please tell me how to auto increment numbers


if i have a sheet with 01 in cell A1 next time i open this sheet i would like it to be 02

does it make sence


many thanks jason
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You can do this with code, but it can be tricky. Do you want the number to increase EVERYTIME the WB is opened??
Big question and you might consider a template

HTH

lenze
 
Upvote 0
yes i would like it everytime thr wb is opened, can you give me some examples of the code or where I can find a template please?
 
Upvote 0
Copy this to

ThisWorkbook
Code:
Public Sub Workbook_Open()
Call test
ThisWorkbook.Save
End Sub



Copy this to new Module
Code:
Sub test()

Dim c, d, i

For c = 2 To 65536

    If Range("A" & c) = 0 Then
    d = c - 1
    i = Range("A" & d)
    GoTo 10
    End If
        
Next c

10 Range("A" & i + 1) = i + 1

End Sub


u will notice that after running the MACRO the excel workbook will save, in order for this to work the workbook has to be saved everytime before u close the excel.... hence made to save automatically before u work on it & close the excel......

Haaa haaa.... I'm new at this MACRO thingy.... so if this is not what u wanted, pls accept my apology
 
Upvote 0
thanks unnilennium78

im getting a compile error

am i doing somthing wrong?

jay
 
Upvote 0
Assuming "Sheet1" :-

Code:
Private Sub Workbook_Open()
Sheets("Sheet1").[A1] = Sheets("Sheet1").[A1] + 1
ThisWorkbook.Save
End Sub

This does not prevent users from changing the value in A1 after the WorkBook is opened.
If you want to do prevent user changes to A1 but don't know how, post again.
 
Upvote 0
thanks unnilennium78

im getting a compile error

am i doing somthing wrong?

jay

Did u copy the correct code the the specified location ......

The Sub workbook Open portion has to be copy to ThisWorkbook

while the

Sub Test has to be copied to a New Module.....

By the way what is ur error ??
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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