ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A way to programmitically lock cells? (https://www.excelbanter.com/excel-programming/298721-way-programmitically-lock-cells.html)

RPIJG[_25_]

A way to programmitically lock cells?
 
Is there a way to programmatically lock cells in a worksheet

--
Message posted from http://www.ExcelForum.com


Harald Staff

A way to programmitically lock cells?
 
Record a macro while doing it and you're almost there.

HTH. Best wishes Harald

"RPIJG " skrev i melding
...
Is there a way to programmatically lock cells in a worksheet?


---
Message posted from http://www.ExcelForum.com/




RPIJG[_26_]

A way to programmitically lock cells?
 
I did this, but now I have a reference to range error, what's wrong wit
this?


Code
-------------------
ActiveWorkbook.Worksheets("Sales Invoice").Range("B2:P57").Select
Selection.Locked = True
Selection.FormulaHidden = False
Worksheets("Customer Invoice").Range("B2:P56").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveWorkbook.Worksheets("Sales Invoice").Range("C19").Selec
-------------------


I did have ActiveWorkbook.Worksheets("Custome
Invoice").Range("B2:P57").Select for that line, and it gave the sam
problem...do I have to activate the worksheet

--
Message posted from http://www.ExcelForum.com


Harald Staff

A way to programmitically lock cells?
 
I said "almost". The errors would probably have to do with either selecting
(unnecessary, you almost never have to select or activate anything) or with
non-existing sheet names (you fix that). For the former, edit down to

Worksheets("Sales Invoice").Range("B2:P57").Locked = True
Worksheets("Customer Invoice").Range("B2:P56").Locked = True

HTH. Best wishes Harald


"RPIJG " skrev i melding
...
I did this, but now I have a reference to range error, what's wrong with
this?


Code:
--------------------
ActiveWorkbook.Worksheets("Sales Invoice").Range("B2:P57").Select
Selection.Locked = True
Selection.FormulaHidden = False
Worksheets("Customer Invoice").Range("B2:P56").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveWorkbook.Worksheets("Sales Invoice").Range("C19").Select
--------------------


I did have ActiveWorkbook.Worksheets("Customer
Invoice").Range("B2:P57").Select for that line, and it gave the same
problem...do I have to activate the worksheet?


---
Message posted from http://www.ExcelForum.com/




RPIJG[_27_]

A way to programmitically lock cells?
 
Thanks, that fixed the problem up perfectly, thanks Haral

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 09:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com