Clear contents of a merged cell

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
4,071
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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
50,527
Office Version
  1. 365
Platform
  1. Windows
You could use either of these
VBA Code:
Range("A3:A4").ClearContents
VBA Code:
Range("A3").MergeArea.ClearContents
 
Solution

KOKOSEK

Active Member
Joined
Apr 8, 2019
Messages
312
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
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
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
4,071
Office Version
  1. 2007
Platform
  1. Windows
Thanks for the advice now sorted
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
50,527
Office Version
  1. 365
Platform
  1. Windows
You're welcome. Glad we could help. :)
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
4,071
Office Version
  1. 2007
Platform
  1. Windows
@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.
 

Forum statistics

Threads
1,141,073
Messages
5,704,141
Members
421,328
Latest member
mippy

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
Top