Vinz B
Vinz B

Reputation: 35

To delete multiple rows by Excel VBA command button

I have a excel sheet with command button to select and delete one row. Deletion can be done only for Rows after 12th row. below is the code I have:-

Sub Button_delete_row()
If ActiveCell.Row > 12 Then
ActiveSheet.Unprotect "xxxx"
Rows(ActiveCell.Row).Delete
ActiveSheet.Protect "xxxx", True, True
End If
End Sub

With my above code in command button, I can select only one row by highlighting with mouse click and deleting. My problem is I want to select multiple rows by highlighting with mouse drag and click on command button to delete these rows.

Upvotes: 0

Views: 732

Answers (1)

smm
smm

Reputation: 100

Perhaps use the following?

Selection.EntireRow.Delete

You can select multiple cells, click the button, and the associated row will be deleted.

Upvotes: 2

Related Questions