Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default ClearContent & 'Cannot change part of a merged cell' error

Hello,

I need to be able to clear the content of all the named cells that
start with "tSel_" - I've created the little function below (I'am a VBA
newbie) and I was able to develop the function below - This works
great, BUT for one thing: If the Named Cell refers to MERGED cells,
this fails with a "Cannot change part of a merged cell." error...

Any suggestions how I can fix this ?

THANKS!!
Richard

Public Function ClearCells()
Dim strFirstletter As String

Set nms = ActiveWorkbook.Names

For i = 1 To nms.Count
strFirstletter = Left(nms(i).Name, 5)
If strFirstletter = "tSel_" Then
nms(i).RefersToRange.ClearContents
End If
Next
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default ClearContent & 'Cannot change part of a merged cell' error

nms(i).RefersToRange.MergeArea.ClearContents

"Richard" wrote:

Hello,

I need to be able to clear the content of all the named cells that
start with "tSel_" - I've created the little function below (I'am a VBA
newbie) and I was able to develop the function below - This works
great, BUT for one thing: If the Named Cell refers to MERGED cells,
this fails with a "Cannot change part of a merged cell." error...

Any suggestions how I can fix this ?

THANKS!!
Richard

Public Function ClearCells()
Dim strFirstletter As String

Set nms = ActiveWorkbook.Names

For i = 1 To nms.Count
strFirstletter = Left(nms(i).Name, 5)
If strFirstletter = "tSel_" Then
nms(i).RefersToRange.ClearContents
End If
Next
End Function


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default ClearContent & 'Cannot change part of a merged cell' error

Works great !

But it seems I get a Run-time error 1004 "Application-Defined or
object-defined error" with groups of merged cells.

For instance, if cells A1 & A2 are merged, and cells B1 & B2 are
merged, the errors appears because tSel_Group represent A1:B2 ... which
is 2 groups of merged cells.

Any workarounds for such ?

THANKS !
Richard

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default ClearContent & 'Cannot change part of a merged cell' error

nms(i).RefersToRange = ""

may work.

Richard wrote:

Hello,

I need to be able to clear the content of all the named cells that
start with "tSel_" - I've created the little function below (I'am a VBA
newbie) and I was able to develop the function below - This works
great, BUT for one thing: If the Named Cell refers to MERGED cells,
this fails with a "Cannot change part of a merged cell." error...

Any suggestions how I can fix this ?

THANKS!!
Richard

Public Function ClearCells()
Dim strFirstletter As String

Set nms = ActiveWorkbook.Names

For i = 1 To nms.Count
strFirstletter = Left(nms(i).Name, 5)
If strFirstletter = "tSel_" Then
nms(i).RefersToRange.ClearContents
End If
Next
End Function


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default ClearContent & 'Cannot change part of a merged cell' error

That did it - THANKS !!

Richard

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 to change cell background color as part of the If statement? Jim H Excel Worksheet Functions 2 September 23rd 09 11:58 PM
Macro to change part of cell Amy Excel Discussion (Misc queries) 2 August 2nd 07 12:43 PM
Why only part of the text is merged from excel cell into word? Mohamed701 Excel Discussion (Misc queries) 6 August 2nd 07 12:31 PM
Keeping one part of a formula same, but change other cell ref? kwelp Excel Discussion (Misc queries) 3 May 17th 05 10:00 PM
Find and clearcontent Dave Peterson[_3_] Excel Programming 0 June 26th 04 04:20 AM


All times are GMT +1. The time now is 08:17 PM.

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"