Sub MergeSelectedCells()
Dim tbl As Table
Dim rng As Range
Dim lCol As Integer
Dim tRow As Integer
Dim rCol As Integer
Dim bRow As Integer
Dim r As Integer
Set tbl = Selection.Range.Tables(1)
tRow = Selection.Cells(1).RowIndex
bRow = Selection.Cells(Selection.Cells.Count).RowIndex
lCol = Selection.Cells(1).ColumnIndex
rCol = Selection.Cells(Selection.Cells.Count).ColumnIndex
For r = tRow To bRow
Set rng = tbl.Cell(r, lCol).Range
rng.End = tbl.Cell(r, rCol).Range.End
rng.Cells.Merge
Next r
|