Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Allow VBA code to change a locked cell??

Hi,

I am using Excel 2007. I have written some VBA code that sets the values in
certain cells using code like the following:

Worksheets("MySheet").Range("A5") = MyValue

This code works when my worksheet is not protected and cell A5 is not
locked. When I protect the worksheet (with A5 locked), my code does not
work. I get run-time error '1004' - "The cell or chart that you are trying
to change is protected and therefore read-only".

I'd like to keep the cell locked (so users cannot edit it), but I do want my
VBA code to be able change the value. Do I have to temporarily unlock the
cell (using VBA) before my code attempts to make a change and then relock the
cell it when my code is done? Or is there an easier way to do this?

Thanks in advance,
Paul
--
Paul Kraemer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Allow VBA code to change a locked cell??

You've got it.
--
HTH,

Barb Reinhardt



"Paul Kraemer" wrote:

Hi,

I am using Excel 2007. I have written some VBA code that sets the values in
certain cells using code like the following:

Worksheets("MySheet").Range("A5") = MyValue

This code works when my worksheet is not protected and cell A5 is not
locked. When I protect the worksheet (with A5 locked), my code does not
work. I get run-time error '1004' - "The cell or chart that you are trying
to change is protected and therefore read-only".

I'd like to keep the cell locked (so users cannot edit it), but I do want my
VBA code to be able change the value. Do I have to temporarily unlock the
cell (using VBA) before my code attempts to make a change and then relock the
cell it when my code is done? Or is there an easier way to do this?

Thanks in advance,
Paul
--
Paul Kraemer

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Allow VBA code to change a locked cell??

I think you'll have to unprotect the sheet prior to the change and reprotect,
rather than unlocking the cell and locking it again.

--
If the post is helpful, please consider donating something to an animal
charity on my behalf.


"Barb Reinhardt" wrote:

You've got it.
--
HTH,

Barb Reinhardt



"Paul Kraemer" wrote:

Hi,

I am using Excel 2007. I have written some VBA code that sets the values in
certain cells using code like the following:

Worksheets("MySheet").Range("A5") = MyValue

This code works when my worksheet is not protected and cell A5 is not
locked. When I protect the worksheet (with A5 locked), my code does not
work. I get run-time error '1004' - "The cell or chart that you are trying
to change is protected and therefore read-only".

I'd like to keep the cell locked (so users cannot edit it), but I do want my
VBA code to be able change the value. Do I have to temporarily unlock the
cell (using VBA) before my code attempts to make a change and then relock the
cell it when my code is done? Or is there an easier way to do this?

Thanks in advance,
Paul
--
Paul Kraemer

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Allow VBA code to change a locked cell??


I ran into the same problem yesterday.

The following code seems to work except for sheets that have chart
objects in them.

Sheets("MySheetName").Protect UserInterfaceOnly:=True

I have found that additional arguments can be added like this:

Sheets("MySheetName").Protect UserInterfaceOnly:=True,
DrawingObjects:=False

I do not fully understand the behavior of these arguments.

I hope that this helps.


--
mgandrud
------------------------------------------------------------------------
mgandrud's Profile: 1541
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=176533

Microsoft Office Help

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
Locked cell Change Message Corey[_4_] Excel Programming 0 December 7th 09 12:34 AM
How do you get a macro not to go to or change a locked cell? bxs02205 Excel Discussion (Misc queries) 2 December 4th 08 03:37 PM
change locked cell if Vincent Excel Discussion (Misc queries) 2 August 22nd 07 02:12 PM
Relacing default Excel message box when user attempts to change locked cell on protected sheet. Chrisso Excel Programming 2 March 19th 07 04:55 PM
Change colour if cell is locked Gary Excel Programming 1 February 19th 04 02:19 AM


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