Prompt Specific Row to Delete

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
Is it possible to prompt the user for a specific row number to delete in a vba textbox? If yes, then the code would fire using a button. I have the worksheet protected and only want to unprotect through code to delete a specific row number, then protect it again.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Maybe something like this:

Code:
Sub test()
Dim MyRow As Long
Sheets("Name").Unprotect "Password"
    MyRow = InputBox("Which Row would you like to delete?")
    Sheets("Name").Range("A" & MyRow).EntireRow.Delete
Sheets("Name").Protect "Password"
End Sub
 
Upvote 0
What happens if the user presses cancel? You might want to cater for that and also if the user enters an invalid row reference.
 
Upvote 0
Good point Colin - 03856me try this:

Code:
Sub DeleteMyRow()

    Dim lngMyRowNum As Long
    
    On Error Resume Next
        lngMyRowNum = CLng(InputBox("Enter the desired row number to be deleted i.e. 50"))
    On Error GoTo 0
    
    If lngMyRowNum = 0 Then 'The user has clicked the <Cancel> button or an invalid number (i.e. text / alphanumeric) was entered
        Exit Sub
    Else
        With ActiveSheet
            .Unprotect "YourPasswordHere"
            .Range("A" & lngMyRowNum).EntireRow.Delete
            .Protect "YourPasswordHere"
        End With
    End If

End Sub

HTH

Robert
 
Last edited:
Upvote 0
Yes, you guys are right, that was a problem, thanks for the help, jproffer code worked like a charm.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top