![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Houston, TX
Posts: 303
|
I need a macro to clear unprotected cells on a protected sheet. If it matters, the cells may contain values or text. Also, this is in Excel2002 which offers lots more options with respect to sheet protection. I tried creating a named range that includes every cell in the print area but once sheet protection is activated, the entire range can't be selected. I would even accept clearing every unprotected cell on the sheet. I'll just bet there's some simple code to do this.
|
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Perth Australia
Posts: 1,567
|
Hi there
You could try something like this: For Each cell In Range("B4:J22") If cell.Locked = False Then cell.ClearContents End If Next End Sub Change the range to your range (works in Excel 2000) regards Derek |
|
|
|
|
|
#3 | ||
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
This will clear unlocked cells rather the worksheet is protected or not... Note: If you do not want to wait around, change this Line: For Each c In ActiveSheet.Cells to a bit smaller range such as: For Each c In range.("A1:Z1000") Quote:
You may also Unprotect a sheet via code at the beginning of you procedure, run your code, and then protect it again. Quote:
Tom |
||
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Didn't mean to repeat you there Derek...
Tom |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Houston, TX
Posts: 303
|
Thanks guys, this will do it.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|