Add one every save to a number

noelmus

Board Regular
Joined
Dec 30, 2018
Messages
105
Hi,
I have this number 000153/19 which indicates Chit No/ Year. I need that every time I save, the Chit No increases by 1 and the year increases by 1 after 31st December.
So for example if I save today, it becomes 000154/19 and if the next save is on 1st January 2020 it becomes 000155/20.

Thanks in advance.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
In ThisWorkbook object with a named cell of "ChitNo" in sheet named sheet1:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  Dim c As Range, a
  Set c = Worksheets("Sheet1").Range("ChitNo")
  c.NumberFormat = "@"
  If InStr(c, "/") = 0 Then
    c = "000001/" & Format(Date, "yy")
    Else
    a = Split(c, "/")
    a(0) = Format(a(0) + 1, "00000#")
    If Format(a(1), "00") <> Format(Date, "yy") Then a(1) = Format(Date, "yy")
    c = Join(a, "/")
  End If
End Sub
 
Upvote 0
Hi,
Already has these codes in work book:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim ws As Worksheet


Set ws = Worksheets("CHIT")
If Sh.Name = ws.Name Then
ws.Range("C12") = Application.UserName
End If


Set ws = Nothing
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("CHIT").Range("J9,J12,C14,E28,E29").Interior.ColorIndex = 6
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,657
Members
449,462
Latest member
Chislobog

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