Deleting contents from merged cells from VBA

A

AVR

I have named 2 merged cells in a spreadsheet, say A1 & B1. The merged cell
is named "range1". I am trying to clear the contents from VBA code, using:
Range("range1").ClearContents
I get an error that says "Cannot change part of a merged cell"
Is there a simple workaround?
Assume I only know the range name and not the component cells.

Thanks
 
I

Incidental

Hi AVR

The following is just modified code from excel help

Option Explicit
Dim Ma As Range

Private Sub CommandButton1_Click()

Set Ma = Range("Range1").MergeArea

If Range("Range1").MergeCells Then

Ma.ClearContents

End If

End Sub

Hope it helps

S
 

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