Hello
I have some VBA which removes a row, based on the cells in a selected column being blank. Its quite powerful, so wanted to add a check that I don’t select an entirely blank column, where all the rows would be deleted (ie the whole sheet).
I therefore wanted to count how many rows it was expecting to remove, and if that totaled all rows in the Sheet, give me a Yes/No warning box. However I'm getting an error.
Can anyone tweak my code to work, including for an entirely blank column.
Thanks. Jay
----
Sub Macro1()
SelectedColumn = ActiveCell.Column
If Columns(SelectedColumn).SpecialCells(xlCellTypeBlanks).CountA = 1048576 Then
MsgBox "You are about to remove all rows in the sheet." & vbCrLf & vbCrLf & "Are you sure you have selected the correct column?", vbYesNo, "Are you sure?"
If vbYes Then
Columns(SelectedColumn).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Else
Exit Sub
End If
Else
Columns(SelectedColumn).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End If
End Sub
I have some VBA which removes a row, based on the cells in a selected column being blank. Its quite powerful, so wanted to add a check that I don’t select an entirely blank column, where all the rows would be deleted (ie the whole sheet).
I therefore wanted to count how many rows it was expecting to remove, and if that totaled all rows in the Sheet, give me a Yes/No warning box. However I'm getting an error.
Can anyone tweak my code to work, including for an entirely blank column.
Thanks. Jay
----
Sub Macro1()
SelectedColumn = ActiveCell.Column
If Columns(SelectedColumn).SpecialCells(xlCellTypeBlanks).CountA = 1048576 Then
MsgBox "You are about to remove all rows in the sheet." & vbCrLf & vbCrLf & "Are you sure you have selected the correct column?", vbYesNo, "Are you sure?"
If vbYes Then
Columns(SelectedColumn).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Else
Exit Sub
End If
Else
Columns(SelectedColumn).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End If
End Sub