Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RAP RAP is offline
external usenet poster
 
Posts: 49
Default Selecting only unlocked cells to clear

Hello,
Can anyone give me the VB code to select all the unlocked-only cells on a
page or in a defined range, to clear them?

Thanks,
Randy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Selecting only unlocked cells to clear

Hi Randy,

I am not aware of any method of selecting unlocked cells, so I would try
something like:

''===========================
Public Sub ClearUnlockedCells()
Dim rcell As Range
Dim rng As Range
Dim CalcMode As Long

Set rng = ActiveSheet.UsedRange '<<======== CHANGE

With Application
.ScreenUpdating = False
CalcMode = .Calculation
.Calculation = xlManual
End With

For Each rcell In rng.Cells
If rcell.Locked = False Then
rcell.ClearContents
End If
Next rcell

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub
'<<===========================


---
Regards,
Norman



"RAP" wrote in message
...
Hello,
Can anyone give me the VB code to select all the unlocked-only cells on a
page or in a defined range, to clear them?

Thanks,
Randy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Selecting only unlocked cells to clear

Randy, here is one way,

Sub Clear_Unlocked_Cells()
Dim Cel As Range
Const Password = "123" '**Change password here**
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=Password
For Each Cel In Range("A1:N25")
If Cel.Locked = False Then Cel.Formula = ""
Next
ActiveSheet.Protect Password:=Password
Application.ScreenUpdating = True
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"RAP" wrote in message
...
Hello,
Can anyone give me the VB code to select all the unlocked-only cells on a
page or in a defined range, to clear them?

Thanks,
Randy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Selecting only unlocked cells to clear

Hi Paul,

Can you not clear unlocked cells without unprotecting / reprotecting the
worksheet?


---
Regards,
Norman



"Paul B" wrote in message
...
Randy, here is one way,

Sub Clear_Unlocked_Cells()
Dim Cel As Range
Const Password = "123" '**Change password here**
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=Password
For Each Cel In Range("A1:N25")
If Cel.Locked = False Then Cel.Formula = ""
Next
ActiveSheet.Protect Password:=Password
Application.ScreenUpdating = True
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"RAP" wrote in message
...
Hello,
Can anyone give me the VB code to select all the unlocked-only cells on a
page or in a defined range, to clear them?

Thanks,
Randy





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default Selecting only unlocked cells to clear

Norman, my bad, yes you can do it, must have been to early in the morning
:)

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"Norman Jones" wrote in message
...
Hi Paul,

Can you not clear unlocked cells without unprotecting / reprotecting the
worksheet?


---
Regards,
Norman



"Paul B" wrote in message
...
Randy, here is one way,

Sub Clear_Unlocked_Cells()
Dim Cel As Range
Const Password = "123" '**Change password here**
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=Password
For Each Cel In Range("A1:N25")
If Cel.Locked = False Then Cel.Formula = ""
Next
ActiveSheet.Protect Password:=Password
Application.ScreenUpdating = True
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"RAP" wrote in message
...
Hello,
Can anyone give me the VB code to select all the unlocked-only cells on

a
page or in a defined range, to clear them?

Thanks,
Randy









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Selecting only unlocked cells to clear

RAP

You need to test the Locked property of the cells, e.g.

For Each cell in Range
If cell.Locked = False Then
cell.ClearContents
End If
Next cell
--
HTH

Simon


"RAP" wrote:

Hello,
Can anyone give me the VB code to select all the unlocked-only cells on a
page or in a defined range, to clear them?

Thanks,
Randy

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
clear unlocked cells macro help please CandiC Excel Worksheet Functions 3 November 13th 09 11:37 PM
paste locked cells and unlocked cells in protected sheet Angeline Excel Worksheet Functions 15 November 1st 06 11:51 PM
Moving from unlocked cells to unlocked cells in an excel form Stacey Lee Excel Worksheet Functions 1 April 24th 06 08:44 PM
Selecting and editing unlocked cells problem John Keith[_2_] Excel Programming 0 April 9th 05 12:05 AM
Selecting first Unlocked Cell jkitzy Excel Programming 0 December 27th 04 08:25 PM


All times are GMT +1. The time now is 07:42 AM.

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"