+ Reply to Thread
Results 1 to 9 of 9

Simple Merge Cells (Macro)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Simple Merge Cells (Macro)

    Hi,

    Please i want some help to do one simple macro;

    i have this table

    eee1 eee2
    1 a
    1 a
    1 b
    1 b
    1 c
    1 c
    1 e
    1 e
    1 e
    1 e

    and i want the macro to do the following output;

    eee1 eee2
    1 a
    1
    1 b
    1
    1 c
    1
    1 e
    1
    1
    1

    as rows A2,3 showing merged cells in column B as "a" in merged rows B2,3

    it is big excel sheet, i mean the column B is very long and i need to merge sometimes 2,3.....20 cells togather.

    please help

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Simple Merge Cells (Macro)

    can you attach a sample file ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Simple Merge Cells (Macro)

    thanks for your reply, please find attached file as requested
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Simple Merge Cells (Macro)

    Sub mergecells()
    LR = Cells(Rows.Count, "A").End(xlUp).Row
    row1 = 2
    eee2 = Cells(row1, 2)
    For j = 3 To LR
      If Cells(j, 2) = eee2 Then
        row2 = j
        Cells(j, 2) = ""
      Else
        With Range("B" & row1 & ":B" & row2)
          .Merge
          .HorizontalAlignment = xlCenter
          .VerticalAlignment = xlCenter
        End With
        row1 = j
        eee2 = Cells(j, 2)
      End If
    Next
    End Sub

  5. #5
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Simple Merge Cells (Macro)

    hi patel,

    i used it in the same file and its working fine, but in another file no, i attached again a sample of the file which i want (2 sheets).

    can u please give me the code again?

    thanks a lot.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Simple Merge Cells (Macro)

    any help plz?

  7. #7
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Simple Merge Cells (Macro)

    any one can help plz?

  8. #8
    Forum Contributor
    Join Date
    12-20-2012
    Location
    Qatar
    MS-Off Ver
    Excel 2010
    Posts
    171

    Re: Simple Merge Cells (Macro)

    ok thanks

    i did it

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,623

    Re: Simple Merge Cells (Macro)

    try
    Sub test()
        Dim myAreas As Areas, myArea As Range
        Sheets("old").Cells.Copy
        With Sheets.Add
            .Cells(1).PasteSpecial
            With .Cells(1).CurrentRegion
                With .Columns(1)
                    Set myAreas = .SpecialCells(4).Areas
                    .VerticalAlignment = xlCenter
                End With
                For Each myArea In myAreas
                    myArea.Cells(0).Resize(myArea.Rows.Count + 1).Merge
                Next
                .AutoFilter
            End With
            .Cells(1).Select
        End With
    End Sub

+ 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