Macro merging

Creating a macro - Writing a Script - Using the API

Macro merging

Postby Diaman » Fri Mar 10, 2017 7:50 pm

I have a list of 1087 names and I need help with a macro to merge cells from 4 columns - A, B, C and D (Output, First name, Middle name and Last name)
I want the full name in cellA (Output) from row 1 to 1087.

A formula is easy but I cant use them for this, and its too much data to do individually.
I have some code below by recording a macro - It shows selecting and merging cells A2 to D2 (and using this i still need to confirm the merge by clicking Yes)

What I hope you can do is give me a loop function that will go through each row and merge the corresponding A to D cells

sub threebecomeone
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("")

rem ----------------------------------------------------------------------
dim args1(0) as new
args1(0).Name = "ToPoint"
args1(0).Value = "$A$2:$D$2"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new
args2(0).Name = "MoveContents"
args2(0).Value = true

dispatcher.executeDispatch(document, ".uno:ToggleMergeCells", "", 0, args2())
OpenOffice 4.1 on Windows
Posts: 1
Joined: Fri Mar 10, 2017 7:01 pm

Re: Macro merging

Postby RoryOF » Fri Mar 10, 2017 8:05 pm

Insert new column A, insert a concatenation formula in A1, select that cell, then pull the formula down with the black square on the bottom right of the selected cell.
Apache OpenOffice 4.1.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
Posts: 23954
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests