Merging two cells into one

S

Steve Wylie

I have a short macro that selects the current cell of a
table, and the one below it, and merges them both into
one cell:

Selection.MoveDown Unit:=wdLine, Count:=1,
Extend:=wdExtend
Selection.Cells.Merge

However this macro does not work when the current cell
contains text of more than one line (because of
the 'Unit:=wdLine' bit, presumably). Is there a
parameter I can use instead of wdLine? It does not seem
to accept wdParagraph or wdTableCell or anything like
that...

Steve Wylie
 
D

DougOliver

Have you tried using the range.information property with
the appropriate parameter to get the actual row number of
the table. Then issue the MoveDown command until the row
number changes
 
J

JGM

Hi Steve,

Try this:

_______________________________________
Selection.Cells(1).Select
Selection.MoveDown Unit:=wdLine, Count:=1, _
Extend:=wdExtend
Selection.Cells.Merge
_______________________________________

or, if you want something more comprehensive,
try fooling around with this:

_______________________________________
Dim MyRange As Range
Dim MyRangeCheck As Range

If Not Selection.Information(wdWithInTable) Then
MsgBox "You must select a cell within a table."
Exit Sub
End If

If Not Selection.Tables(1).Rows.Count = _
Selection.Cells(1).RowIndex Then
Selection.Cells(1).Select
Set MyRange = Selection.Range
Selection.MoveDown Unit:=wdLine, Count:=1, _
Extend:=wdExtend
Set MyRangeCheck = Selection.Range
If MyRange = MyRangeCheck Then
MsgBox "This cell has already been merged."
Exit Sub
End If
Selection.Cells.Merge
Else
MsgBox "You cannot use this macro when a " _
& "cell in the last row is selected."
End If
_______________________________________

HTH
Cheers!
 
S

Steve Wylie

Hi Jean-Guy

Your first fix was enough to do the trick - just what I
wanted. Thanks!

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top