Need code to ignore merged cells in a macro.


Posted by dalton on January 01, 2002 6:01 PM

I have a mcaro that deletes unlocked cells but won't work because it can't "change part of a merged cell".
How do I get the macro to ignore all merged cells?
Thanks



Posted by Ivan F Moala on January 01, 2002 6:44 PM

A couple of ways todo this;
Use On Error resume next OR try and handle the
error condition eg.

Sub clearUnlockedcells()
Dim ocell As Range
Dim datarg As Range

On Error Resume Next
Set datarg = [a1].SpecialCells(xlCellTypeConstants, 23)
If Err Then Exit Sub
For Each ocell In datarg
If ocell.MergeCells = False Then
ocell.Clear
End If
Next
End Sub

Sub clearUnlockedcells_2()
Dim ocell As Range
Dim datarg As Range

On Error Resume Next
Set datarg = [a1].SpecialCells(xlCellTypeConstants, 23)
For Each ocell In datarg
ocell.Clear
Next
End Sub

Ivan