Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default Delete rows from a protected sheet (write macro)

I have a spreadsheet that I want to keep protected. Users are allowed to
change values in certain cells. If need be, they can add a row or delete a
row. I selected to allow this feature before I protected the sheet. The add
row works fine. When a row or rows is/are selected and deleted, a message
pops up indicating there are cells protected. I've written a macro that will
disable the security, delete the rows, and enable the security again. Here
is what I need help with: If the user has not selected at least one row, an
error message will pop up directing the user to do so. Second (if possible)
to make sure the is within a named range: I have named the range A3:A20
"Name". If the row(s) selected does not fall in this range, I want the
delete macro to do nothing or return a message that indicates "The row(s) you
have selected is/are not available to be deleted".
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Delete rows from a protected sheet (write macro)

Give this a look

dim rngIntersect as range
dim rngToDelete as range

set rngtodelete = activecell.entirerow
on error resume next
set rngIntersect = intersect(rngtodelete,
sheets("Sheet1").range("MyRangeName"))
on error goto 0

if rngintersect is nothing then
msgbox "Sorry. Can't delete those rows."
else
rngtoDelete.delete
endif

This will work so long as the user has selected only one row or cell. This
code only deletes the row of the active cell, not the entire selection.
--
HTH...

Jim Thomlinson


"Matt" wrote:

I have a spreadsheet that I want to keep protected. Users are allowed to
change values in certain cells. If need be, they can add a row or delete a
row. I selected to allow this feature before I protected the sheet. The add
row works fine. When a row or rows is/are selected and deleted, a message
pops up indicating there are cells protected. I've written a macro that will
disable the security, delete the rows, and enable the security again. Here
is what I need help with: If the user has not selected at least one row, an
error message will pop up directing the user to do so. Second (if possible)
to make sure the is within a named range: I have named the range A3:A20
"Name". If the row(s) selected does not fall in this range, I want the
delete macro to do nothing or return a message that indicates "The row(s) you
have selected is/are not available to be deleted".

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default Delete rows from a protected sheet (write macro)

Jim-
Thanks.

"Jim Thomlinson" wrote:

Give this a look

dim rngIntersect as range
dim rngToDelete as range

set rngtodelete = activecell.entirerow
on error resume next
set rngIntersect = intersect(rngtodelete,
sheets("Sheet1").range("MyRangeName"))
on error goto 0

if rngintersect is nothing then
msgbox "Sorry. Can't delete those rows."
else
rngtoDelete.delete
endif

This will work so long as the user has selected only one row or cell. This
code only deletes the row of the active cell, not the entire selection.
--
HTH...

Jim Thomlinson


"Matt" wrote:

I have a spreadsheet that I want to keep protected. Users are allowed to
change values in certain cells. If need be, they can add a row or delete a
row. I selected to allow this feature before I protected the sheet. The add
row works fine. When a row or rows is/are selected and deleted, a message
pops up indicating there are cells protected. I've written a macro that will
disable the security, delete the rows, and enable the security again. Here
is what I need help with: If the user has not selected at least one row, an
error message will pop up directing the user to do so. Second (if possible)
to make sure the is within a named range: I have named the range A3:A20
"Name". If the row(s) selected does not fall in this range, I want the
delete macro to do nothing or return a message that indicates "The row(s) you
have selected is/are not available to be deleted".

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete rows while sheet protected loulou Excel Discussion (Misc queries) 3 August 7th 08 09:38 PM
How do I undo write protected to excel sheet send to floppy disk ron Excel Discussion (Misc queries) 1 March 26th 06 08:55 PM
How do I write a macro to delete all rows from the first empty ro. Jon M[_3_] Excel Programming 2 May 12th 05 06:01 PM
how to allow macro to write on a protected sheet MVM Excel Programming 0 January 18th 05 05:05 PM
Macro to look for blank rows in sheet, delete the row and autofit JDerm Excel Programming 1 May 13th 04 07:08 PM


All times are GMT +1. The time now is 09:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"