+ Reply to Thread
Results 1 to 5 of 5

ClearContent & 'Cannot change part of a merged cell' error

  1. #1
    Richard
    Guest

    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. #2
    K Dales
    Guest

    RE: 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. #3
    Richard
    Guest

    Re: 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. #4
    Dave Peterson
    Guest

    Re: 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. #5
    Richard
    Guest

    Re: ClearContent & 'Cannot change part of a merged cell' error

    That did it - THANKS !!

    Richard


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1