Thread: [Solved] merge cells
View Single Post
 
Old 03-02-2012, 10:58 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,385
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your whole post looks as if it's a reply to a post somewhere else. Very confusing.

To merge all of column A, you don't need to know about page breaks. You could use code like:
Code:
Sub Demo()
With ActiveSheet
  .Range("A1", Range("A" & .Cells.SpecialCells(xlCellTypeLastCell).Row)).Merge
End With
End Sub
If you do that to your attached worksheet, though, it'll wipe out all the data, as row 1 is already merged and the result will be the whole of the used range being merged into one cell. Given those considerations, it is not at all clear which range(s) you want to merge. The following macro has code for processing both horizontal and vertical ranges on a page-by-page basis. At present, though, it only displays what those ranges would be, via a message box.
Code:
Sub Demo()
Dim h As Long, i As Long, j As Long, k As Long
With ActiveSheet
  h = .Cells.SpecialCells(xlCellTypeLastCell).Column
  j = 1
  For i = 1 To .HPageBreaks.Count
    If i > 1 Then j = .HPageBreaks(i - 1).Location.Row
    k = .HPageBreaks(i).Location.Row - 1
    MsgBox .Range("A" & k, .Cells(k, h).Address).Address _
      & vbCr & .Range("A" & j, "A" & k).Address
    '.Range("A" & j, .Cells(j, h).Address).Merge
    '.Range("A" & j, "A" & k).Merge
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote