Private Sub Worksheet_Change(ByVal Target As Range)
Dim RowColumnFormula As Boolean
With Target
If .Address = .EntireRow.Address Or .Address = .EntireColumn.Address Then
If .Address = .EntireRow.Address Then
RowColumnFormula = MyTargetHasFormulaRow
Else
RowColumnFormula = MyTargetHasFormulaColumn
End If
If Not Target.Cells.Count = myTargetRowBlanks And Not Target.Cells.Count = myTargetColumnBlanks Or RowColumnFormula Then
If MsgBox("Er staat nog data in de te verwijderen rij(en)/kolom(men), toch verwijderen?", vbYesNo) = vbNo Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End If
End If
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ar As Range, r As Range, c As Range, WholeRow As Boolean, WholeColumn As Boolean
myTargetRowBlanks = 0
myTargetColumnBlanks = 0
MyTargetHasFormulaRow = False
MyTargetHasFormulaColumn = False
For Each ar In Selection.Areas
If Not WholeRow Then WholeRow = ar.Columns.Count = Columns.Count
If Not WholeColumn Then WholeColumn = ar.Rows.Count = Rows.Count
Next
For Each ar In Selection.Areas
For Each r In ar.Rows
If WholeColumn Then Exit For
If WholeRow Then
myTargetRowBlanks = myTargetRowBlanks + WorksheetFunction.CountBlank(r)
If Not MyTargetHasFormulaRow Then MyTargetHasFormulaRow = r.HasFormula
Else
myTargetRowBlanks = myTargetRowBlanks + WorksheetFunction.CountBlank(r.EntireRow)
If Not MyTargetHasFormulaRow Then MyTargetHasFormulaRow = r.EntireRow.HasFormula
End If
Next
For Each c In ar.Columns
If WholeRow Then Exit For
If WholeColumn Then
myTargetColumnBlanks = myTargetColumnBlanks + WorksheetFunction.CountBlank(c)
If Not MyTargetHasFormulaColumn Then MyTargetHasFormulaColumn = c.HasFormula
Else
myTargetColumnBlanks = myTargetColumnBlanks + WorksheetFunction.CountBlank(c.EntireColumn)
If Not MyTargetHasFormulaColumn Then MyTargetHasFormulaColumn = c.EntireColumn.HasFormula
End If
Next
Next
If IsNull(MyTargetHasFormulaRow) Then MyTargetHasFormulaRow = True
If IsNull(MyTargetHasFormulaColumn) Then MyTargetHasFormulaColumn = True
End Sub