How to move contents of cells on 1 page to variable locations on 2nd page

Here is my defining my variables:

Dim oCurrentSelection As Variant
Dim sString As String
dim args1(0) as new com.sun.star.beans.PropertyValue
dim args2(0) as new com.sun.star.beans.PropertyValue
Dim Source as single
Dim Amount as single
dim Donor as String
Dim RDate as double
Dim Move as Integer

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

I then put values or text to the variables and move to sheet2 to a specified location.
I use a Print command to verify the values are loaded into the variables.
I then use the GoDown command by the value of the variable Move.
Thus far, everything works.

The next line is: oCurrentSelection.setValue(Source)

This does not work. The movement works, just the previous line does not.
I get BASIC runtime error Object variable not set.
I’ve tried using an “ActiveCell = Source” to no avail.
Any thoughts on replacing that line with something that would place the contents of the variables in the current cells?

Thank you very much in advance for your help.

I’m kind of new to this, but to me, it looks like you define the variable oCurrentSelection as type Variant, and then assign it the value of Source which has been declared as type Single, but not assigned a value. If ActiveCell is a value of type Single, then your code should be Source = ActiveCell not the other way around.

I doubt if you will get a useful answer based on what you posted.
Post your complete (hopefully not too long) code reduced to one relevant result you expect - and don’t get. Even much better: Attach an example file (.ods).

Also: Be aware of the fact that you won’t get working code in LibreOffice Basic using the API without studying the basics, at least to some degree. Just playing around isn’t the way to learn how to drive a car. Spreadsheet software and programming for it is much more complicated.

The two lines of code you posted only show that you tried to use the dispatcher, most likely based on a recorded macro. Everything else is unclear. ActiveCell points to a VBA background. There isn’t a predefined variable for it in LibreOffice Basic.
Do you actually want to move contents, or just to create a copy?
What about formulas contained in the source cells? What about cell formatting (styles, direct attributes)?
See also:
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1sheet_1_1XCellRangeMovement.html#a094f43e045b0862b58744e62731cbca7

hello @ViMRocks,

i neither understand calc basic macros nor ‘uno’ nor why it’s all cluttered with ‘dispatcher’ … ???

try to work on from the following snippet, it worked for me, i suspect ‘uno’ or ‘the dispatcher’ have a different ‘focus’ than what you access with ‘selection’ … or whatever …

what you need additional is the dispatcher command to set the cell value instead of the current date, i’m in good hope you’ll find it on the web,

sub test_ask

Dim Move as Integer

Move = 10

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 = "$sheet2.$A$2"

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

rem ----------------------------------------------------------------------
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "By"
args3(0).Value = Move
args3(1).Name = "Sel"
args3(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args3())

dispatcher.executeDispatch(document, ".uno:InsertCurrentDate", "", 0, Array())

end sub 'test_ask

P.S. ‘solved marks’ and ‘likes’ welcome,
click the grey circled hook - ✓ - top left to the answer to turn it green if the problem is solved,
click the “^” above it if you ‘like’ the answer,
“v” if you don’t,
do not! use ‘answer’ to add info to your question, either edit the question or add a comment,
‘answer’ only if you found a solution yourself …