Calc - Merge Down Macro


what i want is to only merge columns in a selected range, like the Merge Across Tool in excel but with columns instead. i have seen a previous question Merge Across Tool and i have tried to adapt the code by mark_t but it is still merging rows.

My code:

REM  *****  BASIC  *****

Option Explicit

Sub MergeDown

Dim oCurSelection As Object
Dim oSelRangeAddress As New
Dim i As Long

oCurSelection = thisComponent.CurrentSelection
oSelRangeAddress = oCurSelection.RangeAddress

If oSelRangeAddress.EndRow < oSelRangeAddress.StartRow + 1 Then
    msgbox  "There are no rows to merge."
    Exit Sub
End If

For i = oSelRangeAddress.StartColumn to oSelRangeAddress.EndColumn
    oCurSelection.Spreadsheet. _
        getCellRangeByPosition(oSelRangeAddress.StartRow, i, oSelRangeAddress.EndRow, i). _
Next i

End Sub


Hello @ciaron88,

you could try: oCurSelection.Spreadsheet.getCellRangeByPosition(i, oSelRangeAddress.StartRow, i, oSelRangeAddress.EndRow).merge(True)

Thanks. it now works