Macro to copy a range of cells

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
kierang
Posts: 3
Joined: Fri Aug 17, 2018 5:27 pm

Macro to copy a range of cells

Post by kierang »

I'm new to Macros and want to create a macro which copies a range of cells from the current cell to a number of cells immediately below the current cell.
e.g. copy J2 to J3:J100. So, if I select P4, I want the macro to copy from P4 to P5: Pxxx
I have created the following macro which works from cell I2 but I want it to work from any cell I select i.e the current cell
Can anyone please amend this.
Thanks

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

Sub Main

End Sub


sub Copy
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 = "EndCell"
args1(0).Value = "$I$35"

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

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$I$2:$I$35"

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


end sub
OpenOffice 4 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to copy a range of cells

Post by Villeroy »

1. Copy range
2. Click target cell.
3. Start macro recorder
4. Paste
5. Stop macro recorder.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kierang
Posts: 3
Joined: Fri Aug 17, 2018 5:27 pm

Re: Macro to copy a range of cells

Post by kierang »

Thanks for reply but unable to get this to work.
I want the macro to copy the current cell to a range of cells below.
If I place the mouse in cell E5, I want the macro to copy the contents of E5 to E6:Exxx
OpenOffice 4 on Windows 10
User avatar
MrProgrammer
Moderator
Posts: 4908
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Macro to copy a range of cells

Post by MrProgrammer »

Hi, and welcome to the forum.
kierang wrote:I'm new to Macros and want to create a macro which copies a range of cells from the current cell to a number of cells immediately below the current cell. e.g. copy J2 to J3:J100. So, if I select P4, I want the macro to copy from P4 to P5: Pxxx
For the first example, type J2:J200 in the Name Box (and press Enter) → Edit → Fill → Down.

For the second example, type P4:Pxxx (whatever you want for xxx) in the Name Box (and press Enter) → Edit → Fill → Down. You don't need an evil macro. If you don't know about the Name Box see Help → Index → formula bar;sheet area names.

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.

[Tutorial] Ten concepts that every Calc user should know
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
kierang
Posts: 3
Joined: Fri Aug 17, 2018 5:27 pm

Re: Macro to copy a range of cells

Post by kierang »

Thank you for your input MrProgrammer.
Not exactly what I need.
OpenOffice 4 on Windows 10
Post Reply