Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Anyway to get around "Cannot change part of a merged cell" in VBA?

  1. #1
    Board Regular
    Join Date
    Jul 2017
    Posts
    64
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Anyway to get around "Cannot change part of a merged cell" in VBA?

    Hello, I made a macro to go through a long worksheet and clear out all the entries in certain cells, using the following example code


    Range("G297").Clear
    Range("R297").Clear
    Range("D298").Clear
    Range("L298").Clear
    Range("S298").Clear
    Range("D299").Clear


    I did this for hundreds of cells, typing in the cells I needed to clear, as this sheet will be filled in and cleared regularly. I got tunnel vision while working on this and forgot that all the cells to be cleared are merged, and thus I get the error "Cannot change part of a merged cell". Is there any easy way to fix this, or will I have to go to each of the cells, and make them unmerge and then merge again after they are cleared? Since there's hundreds of them, that'd take a while to type, so I'm hoping there's another way.
    Thanks.

  2. #2
    MrExcel MVP
    Moderator
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    45,526
    Post Thanks / Like
    Mentioned
    34 Post(s)
    Tagged
    4 Thread(s)

    Default Re: Anyway to get around "Cannot change part of a merged cell" in VBA?

    Merged cells are a scourge on VBA and should be avoided whenever possible. The cause all sorts of issues.
    If your cells are merged horizontally, you can achieve the same visual effects as merging without all the issues by using the "Center Across Selection" formatting option instead.
    See: https://www.atlaspm.com/toms-tutoria...merging-cells/
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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