Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AVR AVR is offline
external usenet poster
 
Posts: 14
Default Deleting contents from merged cells from VBA

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Deleting contents from merged cells from VBA

try:

Range("range1").value = ""
or
Range("range1").mergearea.ClearContents

AVR wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
AVR AVR is offline
external usenet poster
 
Posts: 14
Default Deleting contents from merged cells from VBA

..mergearea worked perfectly. Thanks

"Dave Peterson" wrote:

try:

Range("range1").value = ""
or
Range("range1").mergearea.ClearContents

AVR wrote:

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


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Deleting contents from merged cells from VBA

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I delete merged cells in Excel without deleting the final d aries68mc Excel Discussion (Misc queries) 5 March 16th 10 04:42 PM
row height increase automatically to fit contents of merged cells JB Excel Discussion (Misc queries) 1 May 22nd 07 07:37 PM
Clear Contents won't work on merged cells ArthurJ Excel Programming 2 February 20th 06 05:23 PM
Clearing the Contents of Merged Cells prizm1 New Users to Excel 2 September 10th 05 04:42 AM
Clearing the contents of merged cells Doug Glancy Excel Programming 0 April 23rd 04 08:54 PM


All times are GMT +1. The time now is 05:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"