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
Macro to copy a range of cells
Macro to copy a range of cells
OpenOffice 4 on Windows 10
Re: Macro to copy a range of cells
1. Copy range
2. Click target cell.
3. Start macro recorder
4. Paste
5. Stop macro recorder.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Macro to copy a range of cells
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
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
- MrProgrammer
- Moderator
- Posts: 4904
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Macro to copy a range of cells
Hi, and welcome to the forum.
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
For the first example, type J2:J200 in the Name Box (and press Enter) → Edit → Fill → Down.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 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).
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).
Re: Macro to copy a range of cells
Thank you for your input MrProgrammer.
Not exactly what I need.
Not exactly what I need.
OpenOffice 4 on Windows 10