+ Reply to Thread
Results 1 to 7 of 7

Merged Cells quirky behavior

  1. #1
    ArthurJ
    Guest

    Merged Cells quirky behavior

    I have merged cells A1..C1 and named it rngTest.
    I enter data into rngTest.

    Range("rngTest").ClearContents
    'Generates Error 1004 Cannot change part of a merged cell.

    Range("rngTest").Select 'or Activate
    Selection.ClearContents
    'Runs successfully.

    This sure seems bizarre. Does your machine perform like mine? Any suggested
    workarounds? I would prefer NOT to select these cells programmatically.

    Art

  2. #2
    Dave Peterson
    Guest

    Re: Merged Cells quirky behavior

    One way:

    Range("rngTest").value = ""

    or

    Range("rngTest").mergearea.clearcontents



    ArthurJ wrote:
    >
    > I have merged cells A1..C1 and named it rngTest.
    > I enter data into rngTest.
    >
    > Range("rngTest").ClearContents
    > 'Generates Error 1004 Cannot change part of a merged cell.
    >
    > Range("rngTest").Select 'or Activate
    > Selection.ClearContents
    > 'Runs successfully.
    >
    > This sure seems bizarre. Does your machine perform like mine? Any suggested
    > workarounds? I would prefer NOT to select these cells programmatically.
    >
    > Art


    --

    Dave Peterson

  3. #3
    Norman Jones
    Guest

    Re: Merged Cells quirky behavior

    Hi Art,

    Try:

    Range("rngTest").MergeArea.ClearContents


    ---
    Regards,
    Norman


    "ArthurJ" <[email protected]> wrote in message
    news:[email protected]...
    >I have merged cells A1..C1 and named it rngTest.
    > I enter data into rngTest.
    >
    > Range("rngTest").ClearContents
    > 'Generates Error 1004 Cannot change part of a merged cell.
    >
    > Range("rngTest").Select 'or Activate
    > Selection.ClearContents
    > 'Runs successfully.
    >
    > This sure seems bizarre. Does your machine perform like mine? Any
    > suggested
    > workarounds? I would prefer NOT to select these cells programmatically.
    >
    > Art




  4. #4
    Sasa Stankovic
    Guest

    Re: Merged Cells quirky behavior

    it is always better to use ".Select".... this way you are sure Excel knows
    what to select and later than what to do with selection!
    much safer and it doesn't slows down your macro if you are looking for
    optimization....
    "ArthurJ" <[email protected]> wrote in message
    news:[email protected]...
    >I have merged cells A1..C1 and named it rngTest.
    > I enter data into rngTest.
    >
    > Range("rngTest").ClearContents
    > 'Generates Error 1004 Cannot change part of a merged cell.
    >
    > Range("rngTest").Select 'or Activate
    > Selection.ClearContents
    > 'Runs successfully.
    >
    > This sure seems bizarre. Does your machine perform like mine? Any
    > suggested
    > workarounds? I would prefer NOT to select these cells programmatically.
    >
    > Art




  5. #5
    Norman Jones
    Guest

    Re: Merged Cells quirky behavior

    Hi Sasa,

    > it is always better to use ".Select


    Contrawise, I would suggest that selections are rarely necessary or
    desirable and are usually inefficient.


    ---
    Regards,
    Norman



    "Sasa Stankovic" <[email protected]> wrote in message
    news:[email protected]...
    > it is always better to use ".Select".... this way you are sure Excel knows
    > what to select and later than what to do with selection!
    > much safer and it doesn't slows down your macro if you are looking for
    > optimization....
    > "ArthurJ" <[email protected]> wrote in message
    > news:[email protected]...
    >>I have merged cells A1..C1 and named it rngTest.
    >> I enter data into rngTest.
    >>
    >> Range("rngTest").ClearContents
    >> 'Generates Error 1004 Cannot change part of a merged cell.
    >>
    >> Range("rngTest").Select 'or Activate
    >> Selection.ClearContents
    >> 'Runs successfully.
    >>
    >> This sure seems bizarre. Does your machine perform like mine? Any
    >> suggested
    >> workarounds? I would prefer NOT to select these cells programmatically.
    >>
    >> Art

    >
    >




  6. #6
    ArthurJ
    Guest

    Dave, Norman: Got it! Thanks. (eom)



  7. #7
    Peter T
    Guest

    Re: Merged Cells quirky behavior

    You already have good answers from Dave & Norman, so just this-

    > I have merged cells A1..C1 and named it rngTest.


    I expect you only named A1. Had you named A1:C1 your code would work without
    modification.

    If the cells are already merged you'd need to enter the address fully in the
    RefersTo box in the names dialog Ctrl-F3.

    Regards,
    Peter T
    -
    "ArthurJ" <[email protected]> wrote in message
    news:[email protected]...
    > I have merged cells A1..C1 and named it rngTest.
    > I enter data into rngTest.
    >
    > Range("rngTest").ClearContents
    > 'Generates Error 1004 Cannot change part of a merged cell.
    >
    > Range("rngTest").Select 'or Activate
    > Selection.ClearContents
    > 'Runs successfully.
    >
    > This sure seems bizarre. Does your machine perform like mine? Any

    suggested
    > workarounds? I would prefer NOT to select these cells programmatically.
    >
    > Art




+ 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