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

I have a spreadsheet that I am working with in VBA. I have tried making the sheet read only after populating it by using the following code
For i = 1 to
sheet1.Columns(i).Locked = Tru
Nex

However, I am still able to edit all cells. Is there some other syntax that I should use? Can't figure out why this won't work

Thanks much

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Making cells readonly

Sarah

You have to Protect the sheet before locked cells become functional.

Sub lockdown()
With ActiveSheet
For i = 1 To 3
Sheet1.Columns(i).Locked = True
Next
.Protect DrawingObjects:=True, Contents:=True, _
Scenarios :=True
End With
End Sub

The default for Excel is that all cells are "locked" when protection is on.

You may want to "unlock" the other columns before locking up Columns 1 to 3.

Sub lockdown2()
Cells.Select
Selection.Locked = False
Columns("A:C").Locked = True
ActiveSheet.Protect DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub

Gord Dibben Excel MVP



On Sat, 7 Feb 2004 16:46:05 -0800, "Sarah"
wrote:

I have a spreadsheet that I am working with in VBA. I have tried making the sheet read only after populating it by using the following code:
For i = 1 to 3
sheet1.Columns(i).Locked = True
Next

However, I am still able to edit all cells. Is there some other syntax that I should use? Can't figure out why this won't work.

Thanks much.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Making cells readonly

you have to protect the sheet as well.

--
Regards,
Tom Ogilvy


Sarah wrote in message
...
I have a spreadsheet that I am working with in VBA. I have tried making

the sheet read only after populating it by using the following code:
For i = 1 to 3
sheet1.Columns(i).Locked = True
Next

However, I am still able to edit all cells. Is there some other syntax

that I should use? Can't figure out why this won't work.

Thanks much.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Making cells readonly


-----Original Message-----
I have a spreadsheet that I am working with in VBA. I

have tried making the sheet read only after populating it
by using the following code:
For i = 1 to 3
sheet1.Columns(i).Locked = True
Next

However, I am still able to edit all cells. Is there

some other syntax that I should use? Can't figure out why
this won't work.

Thanks much.


Sarah

Locked cells only have an affect if the sheet is protected.
Add code to protect the sheet or do it manualy.

Non formula cells or cells to be edited will have to have
the locked property removed before protecting the sheet

Regards
Peter
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Making cells readonly

When I try the code you had in your post, I get an error: "Expected statement"

Here is the line of code I am using
sheet1.Protect DrawingObjects:=True, Contents:=True, Scenarios:=Tru

Is this not correct



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Making cells readonly

Sub lockdown()

For i = 1 To 3
Sheet1.Columns(i).Locked = True
Next
Sheet1.Protect DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True

End Sub


worked fine for me.

--
Regards,
Tom Ogilvy


Sarah wrote in message
...
When I try the code you had in your post, I get an error: "Expected

statement".

Here is the line of code I am using:
sheet1.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

Is this not correct?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Making cells readonly

Sarah

Either of these will work.

Sub lockdown()
With Sheet1
For i = 1 To 3
.Columns(i).Locked = True
Next
.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True
End With
End Sub


Sub lockdown2()
For i = 1 To 3
Sheet1.Columns(i).Locked = True
Next
Sheet1.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True
End Sub

I still think you should go for the other scenario which unlocks all other
cells except columns 1 to 3

Gord

On Sun, 8 Feb 2004 09:56:05 -0800, "Sarah"
wrote:

When I try the code you had in your post, I get an error: "Expected statement".

Here is the line of code I am using:
sheet1.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

Is this not correct?


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
Changing file from readonly Niall Excel Discussion (Misc queries) 2 July 27th 06 04:58 PM
Readonly files nc Excel Discussion (Misc queries) 2 March 18th 05 11:13 AM
Open As Readonly SCSC[_2_] Excel Programming 5 February 4th 04 05:14 PM
Closing ReadOnly file using VBA acces Excel Programming 1 January 15th 04 08:59 PM
Change ReadOnly State Jos Vens Excel Programming 2 November 17th 03 10:35 PM


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