ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protect cell - VBA (https://www.excelbanter.com/excel-programming/367338-protect-cell-vba.html)

Avi

Protect cell - VBA
 
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


Trevor Shuttleworth

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





All times are GMT +1. The time now is 12:24 PM.

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