Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
KFEagle
 
Posts: n/a
Default Delete contents of unlocked cells in another worksheet

I found some help regarding this as a post to someone elses question.
The solution deletes the formatting in the cells as well. I need to keep
the formatting.
I'm also having trouble running the macro from another worksheet.

The macro is as follows...
this is the macro.....
Sub clear()

Sheets("Payroll - Collections - Pledges").Select
ActiveSheet.Unprotect Password:=Password
Range("C1:AR142").Select <-RIGHT HERE IS WHERE IT HANGS!
Count = 0
On Error Resume Next
For Each RNG In Selection
If RNG.Locked = False Then
Count = Count + 1
If Count = 1 Then Set Unlocked = RNG
If Count < 1 Then Set Unlocked = Union(Unlocked, RNG)
End If
Next RNG
Unlocked.clear <-NEED FORMATTING TO STAY!
ActiveSheet.Protect Password:=Password
End Sub

Thanks!
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Unlocked.clearcontents



KFEagle wrote:

I found some help regarding this as a post to someone elses question.
The solution deletes the formatting in the cells as well. I need to keep
the formatting.
I'm also having trouble running the macro from another worksheet.

The macro is as follows...
this is the macro.....
Sub clear()

Sheets("Payroll - Collections - Pledges").Select
ActiveSheet.Unprotect Password:=Password
Range("C1:AR142").Select <-RIGHT HERE IS WHERE IT HANGS!
Count = 0
On Error Resume Next
For Each RNG In Selection
If RNG.Locked = False Then
Count = Count + 1
If Count = 1 Then Set Unlocked = RNG
If Count < 1 Then Set Unlocked = Union(Unlocked, RNG)
End If
Next RNG
Unlocked.clear <-NEED FORMATTING TO STAY!
ActiveSheet.Protect Password:=Password
End Sub

Thanks!


--

Dave Peterson
  #3   Report Post  
KFEagle
 
Posts: n/a
Default

Thanks Dave, I figured that part out later inthe day. I'm still having
problems with the part about running the macro from another worksheet though.
Any thoughts?

"Dave Peterson" wrote:

Unlocked.clearcontents



KFEagle wrote:

I found some help regarding this as a post to someone elses question.
The solution deletes the formatting in the cells as well. I need to keep
the formatting.
I'm also having trouble running the macro from another worksheet.

The macro is as follows...
this is the macro.....
Sub clear()

Sheets("Payroll - Collections - Pledges").Select
ActiveSheet.Unprotect Password:=Password
Range("C1:AR142").Select <-RIGHT HERE IS WHERE IT HANGS!
Count = 0
On Error Resume Next
For Each RNG In Selection
If RNG.Locked = False Then
Count = Count + 1
If Count = 1 Then Set Unlocked = RNG
If Count < 1 Then Set Unlocked = Union(Unlocked, RNG)
End If
Next RNG
Unlocked.clear <-NEED FORMATTING TO STAY!
ActiveSheet.Protect Password:=Password
End Sub

Thanks!


--

Dave Peterson

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Make sure the code is in a General module. (Do you have it behind a worksheet?)

But you could get rid of some .selects this way:

Option Explicit
Sub clear()

Dim Rng As Range
Dim myCount As Long
Dim Unlocked As Range

With Sheets("Payroll - Collections - Pledges")
.Unprotect Password:="Password"
myCount = 0
Set Unlocked = nothing
For Each Rng In .Range("C1:AR142").Cells
If Rng.Locked = False Then
myCount = myCount + 1
If myCount = 1 Then
Set Unlocked = Rng
Else
Set Unlocked = Union(Unlocked, Rng)
End If
End If
Next Rng
If Unlocked Is Nothing Then
'do nothing
Else
Unlocked.ClearContents
End If
.Protect Password:="Password"
End With
End Sub




KFEagle wrote:

Thanks Dave, I figured that part out later inthe day. I'm still having
problems with the part about running the macro from another worksheet though.
Any thoughts?

"Dave Peterson" wrote:

Unlocked.clearcontents



KFEagle wrote:

I found some help regarding this as a post to someone elses question.
The solution deletes the formatting in the cells as well. I need to keep
the formatting.
I'm also having trouble running the macro from another worksheet.

The macro is as follows...
this is the macro.....
Sub clear()

Sheets("Payroll - Collections - Pledges").Select
ActiveSheet.Unprotect Password:=Password
Range("C1:AR142").Select <-RIGHT HERE IS WHERE IT HANGS!
Count = 0
On Error Resume Next
For Each RNG In Selection
If RNG.Locked = False Then
Count = Count + 1
If Count = 1 Then Set Unlocked = RNG
If Count < 1 Then Set Unlocked = Union(Unlocked, RNG)
End If
Next RNG
Unlocked.clear <-NEED FORMATTING TO STAY!
ActiveSheet.Protect Password:=Password
End Sub

Thanks!


--

Dave Peterson


--

Dave Peterson
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
In Excel how do I delete or change the name of a range of cells? Naming and Deleting a Range Name Excel Discussion (Misc queries) 4 September 21st 08 11:00 PM
How to Delete Contents of D2 if B2 = "SD" StarBoy2000 New Users to Excel 5 July 21st 05 06:46 PM
How do I print a cell's contents as a footer? TC Setting up and Configuration of Excel 1 May 25th 05 11:37 PM
Delete - Shift Cells UP problem Ralph Excel Discussion (Misc queries) 3 March 22nd 05 11:19 PM
How can I merge unlocked cells in a worksheet that has been protec NeedMergeHelp Excel Discussion (Misc queries) 2 December 7th 04 01:20 AM


All times are GMT +1. The time now is 06:45 AM.

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"