Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Locking cells after the user has entered values in protected works

Hi,

I am trying to write a macro that asks a user if they are sure they have
entered the right data, when they answer yes, I want the macro to lock cells
in another spreadsheet. This spreadsheet is password protected, so the user
can only enter data into the cells I now wish to lock. The password example I
give here is ABC. I have written the following code, but get errors.

Sub LockValues()

' Lock the values entered in cells D6 to D23 in Worksheet 1
If MsgBox("Are you sure your entries are " _
& "correct and complete?", vbYesNo) = vbYes _
Then Sheets("Worksheet 1").Select
ActiveSheet.Unprotect Password:="ABC"
Range("D6:D23").Select
Selection.Locked = True
ActiveSheet.Protect "ABC"
End Sub

Can someone advise me what changes I should make?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Locking cells after the user has entered values in protected works

Works for me.

What are the errors you get?

Type and line if possible.

Do you have a Worksheet 1.........note the <space


Gord Dibben MS Excel MVP


On Thu, 13 Dec 2007 13:20:01 -0800, greencecil
wrote:

Hi,

I am trying to write a macro that asks a user if they are sure they have
entered the right data, when they answer yes, I want the macro to lock cells
in another spreadsheet. This spreadsheet is password protected, so the user
can only enter data into the cells I now wish to lock. The password example I
give here is ABC. I have written the following code, but get errors.

Sub LockValues()

' Lock the values entered in cells D6 to D23 in Worksheet 1
If MsgBox("Are you sure your entries are " _
& "correct and complete?", vbYesNo) = vbYes _
Then Sheets("Worksheet 1").Select
ActiveSheet.Unprotect Password:="ABC"
Range("D6:D23").Select
Selection.Locked = True
ActiveSheet.Protect "ABC"
End Sub

Can someone advise me what changes I should make?
Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Locking cells after the user has entered values in protected w

I get a Microsoft Visual Basic window, that has a red cross and the number
400 next to it, with the buttons 'ok' and 'Help' under. When I click on help
a window comes up, but with no contents.
Does this give you any clues about the problem?

"Gord Dibben" wrote:

Works for me.

What are the errors you get?

Type and line if possible.

Do you have a Worksheet 1.........note the <space


Gord Dibben MS Excel MVP


On Thu, 13 Dec 2007 13:20:01 -0800, greencecil
wrote:

Hi,

I am trying to write a macro that asks a user if they are sure they have
entered the right data, when they answer yes, I want the macro to lock cells
in another spreadsheet. This spreadsheet is password protected, so the user
can only enter data into the cells I now wish to lock. The password example I
give here is ABC. I have written the following code, but get errors.

Sub LockValues()

' Lock the values entered in cells D6 to D23 in Worksheet 1
If MsgBox("Are you sure your entries are " _
& "correct and complete?", vbYesNo) = vbYes _
Then Sheets("Worksheet 1").Select
ActiveSheet.Unprotect Password:="ABC"
Range("D6:D23").Select
Selection.Locked = True
ActiveSheet.Protect "ABC"
End Sub

Can someone advise me what changes I should make?
Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Locking cells after the user has entered values in protected w

Where do you have the macro running from?

It should be in a general module.

If in a sheet module other than Worksheet 1 module it will error out because

Range("D6:D23").Select will be referring to the sheet from which the macro was
run, not Worksheet 1


Gord

On Tue, 18 Dec 2007 14:18:01 -0800, greencecil
wrote:

I get a Microsoft Visual Basic window, that has a red cross and the number
400 next to it, with the buttons 'ok' and 'Help' under. When I click on help
a window comes up, but with no contents.
Does this give you any clues about the problem?

"Gord Dibben" wrote:

Works for me.

What are the errors you get?

Type and line if possible.

Do you have a Worksheet 1.........note the <space


Gord Dibben MS Excel MVP


On Thu, 13 Dec 2007 13:20:01 -0800, greencecil
wrote:

Hi,

I am trying to write a macro that asks a user if they are sure they have
entered the right data, when they answer yes, I want the macro to lock cells
in another spreadsheet. This spreadsheet is password protected, so the user
can only enter data into the cells I now wish to lock. The password example I
give here is ABC. I have written the following code, but get errors.

Sub LockValues()

' Lock the values entered in cells D6 to D23 in Worksheet 1
If MsgBox("Are you sure your entries are " _
& "correct and complete?", vbYesNo) = vbYes _
Then Sheets("Worksheet 1").Select
ActiveSheet.Unprotect Password:="ABC"
Range("D6:D23").Select
Selection.Locked = True
ActiveSheet.Protect "ABC"
End Sub

Can someone advise me what changes I should make?
Thanks




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Locking cells after the user has entered values in protected w

Yep, there you have it. I wrote it in the sheet module. Thanks!

"Gord Dibben" wrote:

Where do you have the macro running from?

It should be in a general module.

If in a sheet module other than Worksheet 1 module it will error out because

Range("D6:D23").Select will be referring to the sheet from which the macro was
run, not Worksheet 1


Gord

On Tue, 18 Dec 2007 14:18:01 -0800, greencecil
wrote:

I get a Microsoft Visual Basic window, that has a red cross and the number
400 next to it, with the buttons 'ok' and 'Help' under. When I click on help
a window comes up, but with no contents.
Does this give you any clues about the problem?

"Gord Dibben" wrote:

Works for me.

What are the errors you get?

Type and line if possible.

Do you have a Worksheet 1.........note the <space


Gord Dibben MS Excel MVP


On Thu, 13 Dec 2007 13:20:01 -0800, greencecil
wrote:

Hi,

I am trying to write a macro that asks a user if they are sure they have
entered the right data, when they answer yes, I want the macro to lock cells
in another spreadsheet. This spreadsheet is password protected, so the user
can only enter data into the cells I now wish to lock. The password example I
give here is ABC. I have written the following code, but get errors.

Sub LockValues()

' Lock the values entered in cells D6 to D23 in Worksheet 1
If MsgBox("Are you sure your entries are " _
& "correct and complete?", vbYesNo) = vbYes _
Then Sheets("Worksheet 1").Select
ActiveSheet.Unprotect Password:="ABC"
Range("D6:D23").Select
Selection.Locked = True
ActiveSheet.Protect "ABC"
End Sub

Can someone advise me what changes I should make?
Thanks




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
Locking Cells when user inputs data NervousFred Excel Discussion (Misc queries) 0 August 1st 08 09:34 PM
creating a macro where the values entered in a text box on a user BrianMo Excel Programming 2 September 22nd 06 12:28 PM
Macro for locking cells after worksheet is protected Hugo Excel Programming 4 August 17th 06 09:01 PM
How do I just update values on several cells (not the entire works Jeff Excel Programming 2 March 17th 05 04:53 AM
Locking other cells based on values in a cell. Mario[_6_] Excel Programming 1 January 11th 04 07:41 AM


All times are GMT +1. The time now is 10:42 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"