+ Reply to Thread
Results 1 to 13 of 13

Unmerge All Cells

Hybrid View

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Unmerge All Cells

    Why does this not work? Is it because the first sheet does not have merged cells? If so, how do I check to see that the sheet does not have any merged cells?
    Function CleanBook()
    Dim sh As Worksheet
    
    For Each sh In ActiveWorkbook.Sheets
        sh.Cells.UnMerge
        sh.Name = Trim(sh.Name)
    Next sh
    End Function
    I get "application-defined or object-defined error"
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Unmerge All Cells

    Replace sh.Cells.Unmerge with sh.Cells.MergeCells = False

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,787

    Re: Unmerge All Cells

    How about
    For Each sh In ActiveWorkbook.Sheets
       On Error Resume Next
        sh.Cells.UnMerge
        On Error GoTo 0
        sh.Name = Trim(sh.Name)
    Next sh

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Unmerge All Cells

    Yes, those work but sh.cells.unmerge should work. If the cell is merged, it will unmerge it. It the cell is unmerged it should ignore it.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,787

    Re: Unmerge All Cells

    Best guess is that if there are no merged cells, then Cells.Unmerge effectively returns Nothing

  6. #6
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Unmerge All Cells

    UnMerge applies to a defined cell range. For example. Range("A1:A10").Unmerge. In your example, you are trying to unmerge entire cells on a worksheet, which is a global level method. In summary, if you want to unmerge entire cell, go with MergeCells = False. If you want to unmerge to a defined cell range, go with UnMerge.

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Unmerge All Cells

    The code fails on the first sheet Control Panel which is the sheet I made up and it is "clean." It does not have merged cells and never did.

    Nice call on trim on the sheets. That's not what is happening here, but still, I did not consider it.

    At least I learned one thing that didn't work.

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,787

    Re: Unmerge All Cells

    Nice call on trim on the sheets. That's not what is happening here, but still, I did not consider it.

  9. #9
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Unmerge All Cells

    Suppose I had two sheets (quotes to show the spaces): " Sheet 1" and "Sheet 1 " - TRIM for each would yield "Sheet 1" so when I try to name the second sheet to "Sheet 1" I should get an error.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,787

    Re: Unmerge All Cells

    I get what you're saying, it's just that I can't see anyone mentioning that, hence my confusion.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,454

    Re: Unmerge All Cells

    I suggested it might be an issue in the duplicate thread that Ford has closed ... unfortunately, the posts weren't merged (no pun intended)
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  12. #12
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Unmerge All Cells

    Hmmm, I don't recall posting this twice.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,454

    Re: Unmerge All Cells


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 03-17-2015, 09:47 AM
  2. vba to unmerge cells
    By Ironman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-31-2009, 10:25 AM
  3. unmerge cells
    By Susanstef in forum Excel General
    Replies: 6
    Last Post: 06-26-2006, 10:13 PM
  4. [SOLVED] How do you unmerge cells
    By Freddo in forum Excel General
    Replies: 1
    Last Post: 06-07-2006, 12:10 PM
  5. [SOLVED] Unmerge to all cells possible?
    By Dan von InfoPath in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2006, 05:10 PM
  6. unmerge cells
    By Brian Matlack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2006, 07:10 PM
  7. How do you unmerge cells?
    By Pank Mehta in forum Excel General
    Replies: 1
    Last Post: 02-01-2005, 11:06 AM

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