View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Trevor Shuttleworth Trevor Shuttleworth is offline
external usenet poster
 
Posts: 1,089
Default Protect cell - VBA

Try

Cells(i,j).Locked = True

Regards

Trevor


"Avi" wrote in message
oups.com...
Hi,

I want to protect cells of a particular color usning this code

Sub Protectme()
For i = FirstRow To RowCount 'row
For j = FirstCol To Colcount ' col
If CellColorIndex(Cells(i, j)) = 24 Then
Range.Cells(i,j).Locked = True --- Some problem in this line
End If
Next j
Next i
ActiveSheet.Protect
End Sub

This gives me a run time error.. Can somebody help me ??

Thanks,
Avinash