View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] Nasir.Munir@dal.ca is offline
external usenet poster
 
Posts: 37
Default run time error 9, subscript out of range

Thanks Norman and colofnature !!!

I still have the same error message. Yes it is the existing sheet
colof. Norm I have tried with an array too with all the names(carefully
entered), but it is the same error message. Quite strangely it is
working fine with the first 10 sheets , gives me error for the next 3
sheets and works fine with the last one. Here is my second version of
code, for your review:(gives me error for ENG sheet names)

Sub Hyper2()

Dim name As Variant
name = Array("Colour Page", "CH149", "SLL", "FRI", "CMR", "COS &
Other", _
"DTS", "Maintenance Checks", "LUBRIF", "ENG insp", _
"ENGLCF Calculations", "ENG life", "SB", "MFS Update
Log")
Dim pass

pass = "hiacsc"

Dim cell As Range
For i = 0 To 13
For Each cell In Sheets(name(i)).UsedRange.Cells
Sheets(name(i)).Unprotect (pass)

If cell.HasFormula = True Then
If cell.MergeCells = True Then
With cell.MergeArea
.Locked = True
End With
Else
cell.Locked = True
End If

End If
Next cell
Sheets(name(i)).Protect (pass)
MsgBox (name(i) + " is protected now")
Next i
End Sub




colofnature wrote:
When it breaks, is "sheet_name" an existing sheet?


--
colofnature
------------------------------------------------------------------------
colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356
View this thread: http://www.excelforum.com/showthread...hreadid=559113