macro to merge two table cells?

D

David Newmarch

I've trying unsuccessfully to record a macro that will merge a table cell
with the cell to the right of it. Could anyone suggest code that would do
this?
 
G

Graham Mayor

Sub MergeCellToRight()
Dim oRng As Range
Dim oCell As Cell
Dim i As Long
Set oCell = Selection.Cells(1)
If oCell.ColumnIndex = Selection.Rows(1).Cells.Count Then
MsgBox "There is no cell to the right?", vbCritical, "Error"
Exit Sub
End If
Set oRng = oCell.Range
oRng.MoveEnd wdCell, 1
oRng.Cells.Merge
oCell.Select
Selection.Collapse wdCollapseStart
End Sub


will merge the cell containing the cursor with the cell to the right

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

You are welcome :) Note that the line
Dim i As Long
was not actually used in the posted version of the macro and can be deleted


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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