Article ID: 106390
Article Last Modified on 10/11/2006
Sub Format_Unlocked_Cells()
'Declare procedure-level variables
Dim x As Range, lastcell As Range
'Prevent screen redraw to speed up the macro
Application.ScreenUpdating = False
'Unprotect the worksheet to allow editing
ActiveSheet.Unprotect ("my_password")
'Set lastcell to point to the last cell on the sheet
Set lastcell = Selection.SpecialCells(xlLastCell)
'Place bottom borders on unlocked cells and remove any bottom
'borders from locked cells
For Each x In Range("A1", lastcell)
With x.Borders(xlBottom)
If x.Locked = False Then
.Weight = xlHairline
.ColorIndex = xlAutomatic
Else
.LineStyle = xlNone
End If
End With
Next x
'Re-apply worksheet protection.
ActiveSheet.Protect ("my_password")
End Sub163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 5.00a 5.00c 7.00a XL98 XL97 XL7 XL5
Keywords: kbdtacode kbhowto kbprogramming KB106390