PC Review


Reply
Thread Tools Rate Thread

Assign and clear value to unlocked cells in a protected sheet

 
 
Ram B
Guest
Posts: n/a
 
      1st Aug 2008
I want to create two buttons, one that will give the unlocked cells in a
range H12:H400 the text "Gray" and the other will clear the contents. Any
help will be appriciated.
 
Reply With Quote
 
 
 
 
Dick Kusleika
Guest
Posts: n/a
 
      2nd Aug 2008
On Fri, 1 Aug 2008 08:55:00 -0700, Ram B <(E-Mail Removed)>
wrote:

>I want to create two buttons, one that will give the unlocked cells in a
>range H12:H400 the text "Gray" and the other will clear the contents. Any
>help will be appriciated.


Sub MarkGrey()

Dim rCell As Range

For Each rCell In Sheet1.UsedRange
If Not rCell.Locked Then
rCell.Value = "Gray"
'rcell.ClearContents
End If
Next rCell

End Sub

Make a new sub and change the line to clearcontents for the button to clear.
--
Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com
 
Reply With Quote
 
Ram B
Guest
Posts: n/a
 
      2nd Aug 2008
Thanks - Although this works on the entire sheet, How can get this to a
specific range say range I12:I384, I would like to leave the rest of the
sheet untouched. What I am trying to do is assign specific text to a specific
cllumn by creating a button on the top of the column. I tried this but it
doesnot work

Sub MarkGrey()
Range("I12:I384").Select
Dim rCell As Range

For Each rCell In Worksheets("Passive Safety").UsedRange
If Not rCell.Locked Then
rCell.Value = "Gray"
'rcell.ClearContents
End If
Next rCell

End Sub
"Dick Kusleika" wrote:

> On Fri, 1 Aug 2008 08:55:00 -0700, Ram B <(E-Mail Removed)>
> wrote:
>
> >I want to create two buttons, one that will give the unlocked cells in a
> >range H12:H400 the text "Gray" and the other will clear the contents. Any
> >help will be appriciated.

>
> Sub MarkGrey()
>
> Dim rCell As Range
>
> For Each rCell In Sheet1.UsedRange
> If Not rCell.Locked Then
> rCell.Value = "Gray"
> 'rcell.ClearContents
> End If
> Next rCell
>
> End Sub
>
> Make a new sub and change the line to clearcontents for the button to clear.
> --
> Dick Kusleika
> Microsoft MVP-Excel
> http://www.dailydoseofexcel.com
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      2nd Aug 2008
Sub MarkGrey()

Dim rCell As Range
Dim rng As Range
Set rng = Worksheets("Passive Safety").Range("I12:I384")
For Each rCell In rng
If Not rCell.Locked Then
rCell.Value = "Gray"
'rcell.ClearContents
End If
Next rCell

End Sub


Gord Dibben MS Excel MVP

On Sat, 2 Aug 2008 06:45:05 -0700, Ram B <(E-Mail Removed)>
wrote:

>Thanks - Although this works on the entire sheet, How can get this to a
>specific range say range I12:I384, I would like to leave the rest of the
>sheet untouched. What I am trying to do is assign specific text to a specific
>cllumn by creating a button on the top of the column. I tried this but it
>doesnot work
>
>Sub MarkGrey()
> Range("I12:I384").Select
> Dim rCell As Range
>
> For Each rCell In Worksheets("Passive Safety").UsedRange
> If Not rCell.Locked Then
> rCell.Value = "Gray"
> 'rcell.ClearContents
> End If
> Next rCell
>
>End Sub
>"Dick Kusleika" wrote:
>
>> On Fri, 1 Aug 2008 08:55:00 -0700, Ram B <(E-Mail Removed)>
>> wrote:
>>
>> >I want to create two buttons, one that will give the unlocked cells in a
>> >range H12:H400 the text "Gray" and the other will clear the contents. Any
>> >help will be appriciated.

>>
>> Sub MarkGrey()
>>
>> Dim rCell As Range
>>
>> For Each rCell In Sheet1.UsedRange
>> If Not rCell.Locked Then
>> rCell.Value = "Gray"
>> 'rcell.ClearContents
>> End If
>> Next rCell
>>
>> End Sub
>>
>> Make a new sub and change the line to clearcontents for the button to clear.
>> --
>> Dick Kusleika
>> Microsoft MVP-Excel
>> http://www.dailydoseofexcel.com
>>


 
Reply With Quote
 
Ram B
Guest
Posts: n/a
 
      4th Aug 2008
Thanks guys, It works BUT


It goes at 2 cells a second or in other words it take approx 3 minutes to go
300+ cells. Ansy suggestions as to how I can speed it up?
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Aug 2008
Any chance you have worksheet_change events that fire with each change?

If yes, you could tell excel to stop looking for those changes while your code
does the work.

Sub MarkGrey()

Dim rCell As Range
Dim rng As Range

Set rng = Worksheets("Passive Safety").Range("I12:I384")

application.enableevents = false
For Each rCell In rng
If Not rCell.Locked Then
rCell.Value = "Gray"
'rcell.ClearContents
End If
Next rCell
application.enableevents = true

End Sub

Ram B wrote:
>
> Thanks guys, It works BUT
>
> It goes at 2 cells a second or in other words it take approx 3 minutes to go
> 300+ cells. Ansy suggestions as to how I can speed it up?


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unlocked Cells in Protected Sheet =?Utf-8?B?S01B?= Microsoft Excel Worksheet Functions 3 8th Nov 2007 07:08 PM
paste locked cells and unlocked cells in protected sheet =?Utf-8?B?YW5nZWxpbmU=?= Microsoft Excel Worksheet Functions 15 1st Nov 2006 11:51 PM
move between unlocked cells on protected sheet =?Utf-8?B?YXlhbm5h?= Microsoft Excel Misc 1 27th Apr 2005 05:59 PM
Formatting unlocked cells on protected sheet Lee Schipper Microsoft Excel Programming 1 13th Apr 2005 08:00 PM
Protected sheet and unlocked cells Flynn Microsoft Excel Misc 2 16th Jul 2004 01:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:44 PM.