This code, when put in the sheet's code module, will detect when a row is deleted. If there is a whole column reference formula, like =COUNTA(E:E) somewhere.If nobody find any trick, if you wanna stay absolutely with the actual check boxes design and still with the manual row deletion,I see some clunky way but as your workbook is a bit heavy …The idea is to use some VBA event, like when the worksheet is activated or desactivated or when the workbook is saved whatever,to find out for some 'ghost check boxes' by comparing their cell addresses and if they are behind other check boxes …Maybe someone else may expose a better idea …
' in a sheet's code module
Dim lastRow As Range
Private Sub Worksheet_Calculate()
On Error GoTo Out
If lastRow.Rows.Count > 1 Then
MsgBox "row " & Selection.Row & " was deleted"
End If
Out:
Rem row inserted
Set lastRow = Rows(Rows.Count)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set lastRow = Rows(Rows.Count)
End Sub
Option Explicit
Private oCol As Collection, SearchRange As Range, lSearchRangeRowsCount As Long
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim oChBx As CheckBox, oCell As Range
Dim lPrevLRW As Long, lPrevLRC As Long, llastRow As Long, llastCol As Long
For Each oChBx In Sh.CheckBoxes
llastRow = Application.Max(oChBx.TopLeftCell.Row, lPrevLRW)
llastCol = Application.Max(oChBx.TopLeftCell.Column, lPrevLRC)
lPrevLRW = llastRow
lPrevLRC = llastCol
Next
Set SearchRange = Sh.Range(Cells(1, 1), Cells(llastRow + 1, llastCol + 1))
lSearchRangeRowsCount = SearchRange.Rows.Count
Set oCol = New Collection
On Error Resume Next
For Each oCell In Intersect(SearchRange, Target.EntireRow).Cells
For Each oChBx In Sh.CheckBoxes
If oChBx.TopLeftCell.Row = oCell.Row Then
oCol.Add oChBx, CStr(oChBx.Name)
End If
Next oChBx
Next oCell
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim oChBx As CheckBox
If SearchRange.Rows.Count < lSearchRangeRowsCount Then
For Each oChBx In oCol
oChBx.Delete
Next oChBx
End If
End Sub
ZOrder
method : a gas factory code may start hereTopLeftCell
address according to their ZOrderPosition
…