macro crashes excell xp

T

Todd

Hi,

I am using this macro to bold all my locked cells and it
crashes Excel unless I restrict its range to very small
areas. I would like to let it run through the entire
workbook. Can someone help me clean up the code so it
does not crash?


Thanks,


Todd




Sub BoldLocked()
For Each cell In Selection.Cells
If cell.Locked = True Then
cell.Font.Bold = True
End If
If cell.Locked = False Then
cell.Font.Bold = False
End If
Next cell
MsgBox "No more cells to check"
End Sub
 
S

Seth

Well, here is what I would do to clean up the code:

For Each Cell In Selection.Cells
Cell.Font.Bold = Cell.Locked
Next Cell
MsgBox "No more cells to check"

I am not sure why it is crashing with this
code...remember that a valid selection needs to exist, so
some error handling is warranted (what if a chart is
selected?).

Hope this helps.

Seth
 
D

Don Guillett

You might like this better.

Sub lockbold()
Application.ScreenUpdating = False
Application.Calculation = xlManual
For Each ws In Sheets
For Each cell In ws.UsedRange
If cell.Locked = True Then cell.Font.Bold = True
Next cell
Next ws
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
MsgBox "No more cells to check"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top