That's a really a stupid way.
Add CANCEL to the named range
Sub test()
Dim x, s(1)
With ActiveSheet
If .[d2] = "" Then Exit Sub
If .[d2] = "CANCEL" Then
If .Name = "CANCEL" Then
.Columns("g").Resize(, .Cells.SpecialCells(11).Column - 7).Replace .[d6], "", 1
.[d6].ClearContents
End If
Else
x = Application.Match(.[d2], .Rows(1), 0)
s(0) = .Cells(Rows.Count, x).End(xlUp)
s(1) = Format$(Val(Right$(s(0), 3)) + 1, "000")
s(0) = Left(s(0), Len(s(0)) - 3)
.[d6] = Join(s, "")
.Cells(Rows.Count, x).End(xlUp)(2) = Join(s, "")
End If
End With
End Sub
Bookmarks