Clear contents of a merged cell

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
I have some text in cell A3 which is merged with cell A4

In a line of code i use i have the following.
Rich (BB code):
Range("A3").ClearContents

I see the error message "Cant change part of a merged cell"
I click ok etc but the value in the cell A3 is cleared no problem.
How can i clear the contents without the error message.

Please advise thanks.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You could use either of these
VBA Code:
Range("A3:A4").ClearContents
VBA Code:
Range("A3").MergeArea.ClearContents
 
Upvote 0
Solution
Try this way:

VBA Code:
Sub ClearEvenMerged()
For Each cell In [A1:A10]
    If cell.MergeCells Then
        cell.MergeArea.ClearContents
    Else
        cell.ClearContents
    End If
Next cell
End Sub
 
Upvote 0
@Peter_SSs

Would you mind taking a quick look please at this post.

Just need to get the code in correct order for the saved file name.

Thanks & have a nice day.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top