Message Box: Delete row x?

T

Tami

i have a macro designed to allow a user to delete a row in a protected
worksheet.
In the message box, i'd like to prompt the user as follows:
"Are you sure you want to delete row x?" with X being the row number of
where the cursor is currently sitting.
thanks in advance,
tami
 
D

Dave Peterson

Option Explicit
Sub testme()
Dim resp As Long
resp = MsgBox(Prompt:="Are you sure you want to delete row " & ActiveCell.Row, _
Buttons:=vbYesNo)
If resp = vbYes Then
'unprotect the sheet
ActiveCell.EntireRow.Delete
'protect the sheet
End If
End Sub
 
T

Tami

perfect!
thanks much!
tami

Dave Peterson said:
Option Explicit
Sub testme()
Dim resp As Long
resp = MsgBox(Prompt:="Are you sure you want to delete row " & ActiveCell.Row, _
Buttons:=vbYesNo)
If resp = vbYes Then
'unprotect the sheet
ActiveCell.EntireRow.Delete
'protect the sheet
End If
End Sub
 
S

Shane Devenshire

Hi,

If you protect the sheet in code with a line like

ActiveSheet.Protect Password:="x", userinterfaceonly:=True

Then there is no need to unprotect and reprotect within the macro.

You can run this as a standalone macro or incorporate it into a
Workbook_Open routine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Using a macro to enter a formula 4
Macro for Insert/ Copied Cells 2
application.goto 4
Edit REplace String 2
Userinterfaceonly 5
Downward column 1
Data moving 2 7
Insert/ delete row in protected worksheet 7

Top