Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Clear Contents won't work on merged cells

I have merged cells C1 and D1, and named it 'mergedCells'.
But I get a "400" error from the following VBA code:

[mergedCells].ClearContents

That seems odd. Is there a workaround?

Art
  #2   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default Clear Contents won't work on merged cells

You have to reference all of the cells that are merged. In your example the
following should work...

Range("C1:D1").clearcontents

It's not enough to reference the first of the merged cells (which is
bothersome because in other instances, like copy, you can reference the first
of the merged cells only)

"ArthurJ" wrote:

I have merged cells C1 and D1, and named it 'mergedCells'.
But I get a "400" error from the following VBA code:

[mergedCells].ClearContents

That seems odd. Is there a workaround?

Art

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Clear Contents won't work on merged cells

This demo from the immediate window worked for me:

Range("C1:D1").Merge
Range("C1").MergeArea.Name = "MergedCells"
rANGE("c1").Value = "Merged Cells"
? range("C1").Value
Merged Cells
? Range("MergedCells").Address
$C$1:$D$1
Range("MergedCells").ClearContents

IF it is a 400 error in a dialog with a circled red X or something like that
and no message, I believe that is caused by a bug in Excel, not trying to
clearcontents. Try closing and reopening excel and the workbook.

Tested in xl2002
--
Regards,
Tom Ogilvy


"ArthurJ" wrote in message
...
I have merged cells C1 and D1, and named it 'mergedCells'.
But I get a "400" error from the following VBA code:

[mergedCells].ClearContents

That seems odd. Is there a workaround?

Art



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
Macro to clear contents of certain cells MrAcquire Excel Discussion (Misc queries) 3 February 11th 10 05:25 PM
Clear contents of cells if a condition is met bevchapman Excel Worksheet Functions 2 March 16th 09 03:45 PM
Clear Contents Of Cells Where Value = 0 carl Excel Worksheet Functions 3 July 6th 07 06:02 PM
clear cells unless contents are in bold John Jones Excel Programming 1 August 24th 05 01:07 PM
Clear Contents - NonBold cells Steve Excel Discussion (Misc queries) 3 February 13th 05 11:36 PM


All times are GMT +1. The time now is 06:09 AM.

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

About Us

"It's about Microsoft Excel"