Page 1 of 1

Macro merging

Posted: Fri Mar 10, 2017 7:50 pm
by Diaman
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("com.sun.star.frame.DispatchHelper")

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

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

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "MoveContents"
args2(0).Value = true

dispatcher.executeDispatch(document, ".uno:ToggleMergeCells", "", 0, args2())

Re: Macro merging

Posted: Fri Mar 10, 2017 8:05 pm
by RoryOF
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.