Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sheet protection



Several days ago I did a newsgroup query and got an excellent response
to my coding problem that really works well. Now I want to protect the
worksheet and when I do I get a run time error at line 9. Is there a
line of code that I can insert to allow me to do this?

Thank You
Carl

Private Sub Worksheet_Change(ByVal _
Target As Excel.Range)
Dim rng as Range
If Target.Count 1 Then Exit Sub
If Target.row = 2 and Target.Row <=10 then
If Target.column = 5 Then
If Not IsEmpty(Target) Then
If IsNumeric(Target) Then
Application.EnableEvents = False
set rng = Target.Offset(0,4)
rng.Value = rng.value + Target.Value
Target.ClearContents
Application.EnableEvents = True
End If
End If
End If
End If
End Sub



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Sheet protection

Hello Rev,

You can unprotect the worksheet in VBA before you make
modifications to the worksheet, then reprotect it after
you are done with your modifications. Like the following:

Worksheets("Sheet1").Unprotect
'Code to change the worksheet
Worksheets("Sheet1").Protect

You could do this around all of your code if you want, if
you make several modifications in several places, or you
could just put this around the code that actually
modifies the worksheet. Look up the .protect
and .unprotect methods in the VBA help for additional
information.

Hope this helps,

Kris

-----Original Message-----


Several days ago I did a newsgroup query and got an

excellent response
to my coding problem that really works well. Now I want

to protect the
worksheet and when I do I get a run time error at line

9. Is there a
line of code that I can insert to allow me to do this?

Thank You
Carl

Private Sub Worksheet_Change(ByVal _
Target As Excel.Range)
Dim rng as Range
If Target.Count 1 Then Exit Sub
If Target.row = 2 and Target.Row <=10 then
If Target.column = 5 Then
If Not IsEmpty(Target) Then
If IsNumeric(Target) Then
Application.EnableEvents = False
set rng = Target.Offset(0,4)
rng.Value = rng.value + Target.Value
Target.ClearContents
Application.EnableEvents = True
End If
End If
End If
End If
End Sub



*** Sent via Developersdex http://www.developersdex.com

***
Don't just participate in USENET...get rewarded for it!
.

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
Excel Data Protection Best Practice: AKA: Real Sheet Protection Mushman(Woof!)[_2_] Excel Discussion (Misc queries) 4 December 30th 09 01:20 AM
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Setting up and Configuration of Excel 0 December 29th 09 06:50 AM
Sheet protection Smitty Excel Discussion (Misc queries) 7 January 11th 09 12:26 AM
Sheet protection error msg - Unrequested sheet activation deltree[_3_] Excel Programming 0 January 28th 04 06:20 PM
Sheet Protection Mike Excel Programming 2 January 1st 04 05:25 PM


All times are GMT +1. The time now is 02:15 PM.

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"