Keep counting from workbook to workbook

noelmus

Board Regular
Joined
Dec 30, 2018
Messages
105
Hi,
I have 2 workbooks ("Invoice1" and "Invoice2") which are identical
In Workbook "Invoice1" sheets (CHIT1&2,CHIT3&4 and CHIT5&6) have cell J8 updates by double click cell K8 by a code, so if I double click cell K8 in one of the sheets, cell J8 will update in all 3 sheets. So cell J8 in these 3 sheets must always be the same.
Now I need that cell J8 (always in the 3 sheets) in Workbook "Invoice2" will continue counting on that of Workbook "Invoice1". For example if the last value of cell J8 in Workbook "Invoice1" was 000075/19, then cell J8 in Workbook "Invoice2" will start with 000075/19.
This is the code in ThisWorkbook.
Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    Dim c As Range, a
    If Target.Address = "$K$8" Then
        ' Don't edit the cell
        Cancel = True
        ' Increment the invoice nunber
        
        Set c = Sheets("CHIT5&6").Range("J8")
        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
        Set c = Sheets("CHIT3&4").Range("J8")
        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
        '
        Set c = Sheets("CHIT1&2").Range("J8")
        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 If
End Sub


Thanks in advance
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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