Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Protecting only certain cells in Excel

Status
Not open for further replies.

dyana

Technical User
Mar 26, 2002
27
US
Let's say that I have a range from a1:z30, and I want to protect cells based on the following criteria.

(1) everything should be protected except for items specified in (2)

(2) Rows that have "Forecast" in column "H" should only be protected through a certain column number that will be referenced in column "AA" on the same row. The column number referenced in "AA" will change each time this model is run.

(3) This protection process for the phase show in (2) needs to occur until column "H" is blank.

I appreciate any help.
dyana
 
I think this should work for you if I understand your question.

Sub Lock_Cells()
Dim numcolumns As Integer
Dim x As Integer

ActiveSheet.Unprotect
Sheets(1).Select
Range("a1:z30").Locked = True
Cells(1, 8).Select 'column H is 8
x = 1
Do Until ActiveCell = ""
If ActiveCell = "Forcast" Then
numcolumns = Cells(ActiveCell.Row, 27) '27 is AA
Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, numcolumns)).Locked = False
End If
x = x + 1
Cells(x, 8).Select
Loop
ActiveSheet.Protect
End Sub

Hope this is helpful

ts2032
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top