Ask Your Question

Calc - Merge Down Macro [closed]

asked 2017-07-29 15:03:09 +0200

ciaron88 gravatar image

updated 2020-07-22 07:47:21 +0200

Alex Kemp gravatar image


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


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-07-22 07:47:29.031646

1 Answer

Sort by » oldest newest most voted

answered 2017-07-29 15:52:12 +0200

librebel gravatar image

Hello @ciaron88,

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

edit flag offensive delete link more


Thanks. it now works

ciaron88 gravatar imageciaron88 ( 2017-07-29 20:13:56 +0200 )edit

Question Tools

1 follower


Asked: 2017-07-29 15:03:09 +0200

Seen: 304 times

Last updated: Jul 29 '17