Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default clearing unlocked fields on a protected sheet

I know that my cmd button code can unlock a worksheet, then step through a
list of named ranges to clear, but is there a better way, say using "For
each...next" to step trhough each cell in a named range to test for the
"unlocked" cells, then clearing? Can you address each cell as a range in a
collection of ranges using For...each?

DM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default clearing unlocked fields on a protected sheet

Yes, there is an easy way to step through your range, e.g:
Dim CheckCell as Range

For Each CheckCell in Range("MyNamedRange").Cells
If CheckCell.Locked=False then CheckCell.ClearContents
Next CheckCell


"Dick Minter" wrote:

I know that my cmd button code can unlock a worksheet, then step through a
list of named ranges to clear, but is there a better way, say using "For
each...next" to step trhough each cell in a named range to test for the
"unlocked" cells, then clearing? Can you address each cell as a range in a
collection of ranges using For...each?

DM

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default clearing unlocked fields on a protected sheet

Dick,

Do you mean something like this?

Sub test()
Dim cell As Range
Dim range_to_clear As Range

With ActiveSheet
Set range_to_clear = Union(.Range("test_range_1"),
..Range("test_range_2"))
End With
For Each cell In range_to_clear
If cell.Locked = False Then
cell.ClearContents
End If
Next cell
End Sub

hth,

Doug Glancy

"Dick Minter" wrote in message
...
I know that my cmd button code can unlock a worksheet, then step through a
list of named ranges to clear, but is there a better way, say using "For
each...next" to step trhough each cell in a named range to test for the
"unlocked" cells, then clearing? Can you address each cell as a range in

a
collection of ranges using For...each?

DM



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default clearing unlocked fields on a protected sheet

Put this in your code
replace
MsgBox cel.Address
with your code

To clear the cel use
cel.ClearContents

It is not necessary to unprotect if you are only changing the
unprotected cells.
==========================
Dim cel As Range, rng As Range

Set rng = ActiveSheet.Range("A1:A10")

For Each cel In rng
If cel.Locked = False Then
MsgBox cel.Address
End If
Next
=============================

--
steveB

Remove "AYN" from email to respond
"Dick Minter" wrote in message
...
I know that my cmd button code can unlock a worksheet, then step through a
list of named ranges to clear, but is there a better way, say using "For
each...next" to step trhough each cell in a named range to test for the
"unlocked" cells, then clearing? Can you address each cell as a range in
a
collection of ranges using For...each?

DM



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default clearing unlocked fields on a protected sheet

How do you deal with merged cells? When the indicated cell is merged with
another, an error occurs. Would it be better to use a Userform with text box
objects?

DM

"STEVE BELL" wrote:

Put this in your code
replace
MsgBox cel.Address
with your code

To clear the cel use
cel.ClearContents

It is not necessary to unprotect if you are only changing the
unprotected cells.
==========================
Dim cel As Range, rng As Range

Set rng = ActiveSheet.Range("A1:A10")

For Each cel In rng
If cel.Locked = False Then
MsgBox cel.Address
End If
Next
=============================

--
steveB

Remove "AYN" from email to respond
"Dick Minter" wrote in message
...
I know that my cmd button code can unlock a worksheet, then step through a
list of named ranges to clear, but is there a better way, say using "For
each...next" to step trhough each cell in a named range to test for the
"unlocked" cells, then clearing? Can you address each cell as a range in
a
collection of ranges using For...each?

DM






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default clearing unlocked fields on a protected sheet

This replaces the contents with ""
(looks blank, but isn't)
(works on column A through rows 10)

You're right - you can't clear merged cells.
But this works.

Dim x As Long

For x = 1 To 10
If Cells(x, 1).Locked = False Then
Cells(x, 1) = ""
End If
Next


--
steveB

Remove "AYN" from email to respond
"Dick Minter" wrote in message
...
How do you deal with merged cells? When the indicated cell is merged with
another, an error occurs. Would it be better to use a Userform with text
box
objects?

DM

"STEVE BELL" wrote:

Put this in your code
replace
MsgBox cel.Address
with your code

To clear the cel use
cel.ClearContents

It is not necessary to unprotect if you are only changing the
unprotected cells.
==========================
Dim cel As Range, rng As Range

Set rng = ActiveSheet.Range("A1:A10")

For Each cel In rng
If cel.Locked = False Then
MsgBox cel.Address
End If
Next
=============================

--
steveB

Remove "AYN" from email to respond
"Dick Minter" wrote in message
...
I know that my cmd button code can unlock a worksheet, then step through
a
list of named ranges to clear, but is there a better way, say using
"For
each...next" to step trhough each cell in a named range to test for the
"unlocked" cells, then clearing? Can you address each cell as a range
in
a
collection of ranges using For...each?

DM






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default clearing unlocked fields on a protected sheet

Dick,

I think you can use "MergeArea.ClearContents" as below:

Sub test()
Dim cell As Range
Dim range_to_clear As Range

With ActiveSheet
Set range_to_clear = Union(.Range("test_range_1"),
..Range("test_range_2"))
End With
For Each cell In range_to_clear
If cell.Locked = False Then
cell.MergeArea.ClearContents
End If
Next cell
End Sub

hth,

Doug

"Dick Minter" wrote in message
...
How do you deal with merged cells? When the indicated cell is merged with
another, an error occurs. Would it be better to use a Userform with text

box
objects?

DM

"STEVE BELL" wrote:

Put this in your code
replace
MsgBox cel.Address
with your code

To clear the cel use
cel.ClearContents

It is not necessary to unprotect if you are only changing the
unprotected cells.
==========================
Dim cel As Range, rng As Range

Set rng = ActiveSheet.Range("A1:A10")

For Each cel In rng
If cel.Locked = False Then
MsgBox cel.Address
End If
Next
=============================

--
steveB

Remove "AYN" from email to respond
"Dick Minter" wrote in message
...
I know that my cmd button code can unlock a worksheet, then step

through a
list of named ranges to clear, but is there a better way, say using

"For
each...next" to step trhough each cell in a named range to test for

the
"unlocked" cells, then clearing? Can you address each cell as a range

in
a
collection of ranges using For...each?

DM






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
Unlocked Cells in Protected Sheet KMA Excel Worksheet Functions 3 November 8th 07 07:08 PM
How do I create a comment on an unlocked cell in a protected sheet LObeidat Excel Discussion (Misc queries) 1 July 25th 06 01:14 PM
allow comments, unlocked cells, protected sheet Jeff Higgins Excel Programming 3 October 7th 05 02:43 PM
move between unlocked cells on protected sheet ayanna Excel Discussion (Misc queries) 1 April 27th 05 05:59 PM
Formatting unlocked cells on protected sheet Lee Schipper Excel Programming 1 April 13th 05 08:00 PM


All times are GMT +1. The time now is 01:14 PM.

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

About Us

"It's about Microsoft Excel"