ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protecting merged cells via Macro (https://www.excelbanter.com/excel-programming/352022-protecting-merged-cells-via-macro.html)

Shane in Canberra

Protecting merged cells via Macro
 
Hi,

Hopefully a simple question. How can I change the protection on merged
cells? The following line of code gives me an error if there are merged
cells in the named range, but works fine if the named range contains no
merged cells:

range("mergedcells").locked = true


Thanks in advance
Shane

[email protected]

Protecting merged cells via Macro
 
I tried this and was unable to duplicate your problem. Could you give
some additional information.


Ken Johnson

Protecting merged cells via Macro
 
Hi Shane,
the range has to be unmerged before being locked, so try

Range("mergedcells").UnMerge
Range("mergedcells").Locked = True
Range("mergedcells").Merge

Ken Johnson


Ken Johnson

Protecting merged cells via Macro
 
I should have used a With/End With...

With Range("mergedcells")
..Unmerge
..Locked = True
..Merge
End With

Ken Johnson



All times are GMT +1. The time now is 11:32 AM.

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