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.
Thanks in advance
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: