echox
echox

Reputation: 9860

Unlocking range of cells in excel selected by cellname Office 2007

I have 3 cells which are merged with each other and are referenced to with a given cellname (for example "foo").

I now want to unlock these cells with the locked attribute.

The lock in the following code will not work, but the value will be successfully assigned to the cell:

Workbooks(loadedSheetName).Worksheets("foo").Range("bar").Locked = False
Workbooks(loadedSheetName).Worksheets("foo").Range("bar") = "foo value"

What will work is referencing the cells by "coordinates" but is not really an option for me:

Workbooks(loadedSheetName).Worksheets("foo").Range("B3:E3").Locked = False

Is there any possibility to select some merged cells by name and set the locked attribute to false?

Upvotes: 1

Views: 9603

Answers (2)

Fandango68
Fandango68

Reputation: 4898

You don't need to go through every cell in a Range.

Simply...

 Range("myRangeName").Select
 Selection.Locked = False

Upvotes: 0

Dr. belisarius
Dr. belisarius

Reputation: 61056

The following code works OK in my Excel 2007


Sub aa()
    Dim ce As Range
    Application.ScreenUpdating = False ''# screen flicker off
    ActiveSheet.Unprotect Password:=""
    For Each ce In Range("rng")
        ce.MergeArea.Locked = "False"
    Next ce
    ActiveSheet.Protect Password:=""
End Sub

HTH!

Upvotes: 3

Related Questions