Hi Karolus
I am posting this macro to see if you or anyone thinks it will work with LibreOffice calc macos.
REM ***** BASIC *****
Sub CopyPricesToPriceHistoryRev1
REM created by 12Feb24
dim document as object
dim dispatcher as object
REM get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
REM Define sheet names
oDocument = ThisComponent 'assigns the current document to the variable document
Controller = oDocument.getcurrentController
oSheets =oDocument.Sheets
priceSheet = oSheets.getByName("Prices")
histSheet = oSheets.getByName("Price History")
REM make Prices sheet active
Controller.setActiveSheet(priceSheet)
REM copy cells D4 to D38 on Prices sheet
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ToPoint"
args3(0).Value = "$D$4:$D$43"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
REM Make Price History sheet active
Controller.setActiveSheet(histSheet)
REM Find the first empty column in row 4 in the Prices History sheet
eCells = histSheet.Rows(3).QueryEmptyCells
finRg = eCells(eCells.Count - 1)
If finRg.RangeAddress.EndColumn<>histSheet.RangeAddress.endColumn Then Exit Sub
target = finRg.GetCellByPosition(0, 0)
oDocument.CurrentController.Select(target)
REM get address of cell to paste to
oActivecell = ThisComponent.CurrentSelection
oConv = oDocument.createInstance("com.sun.star.table.CellAddressConversion")
oConv.Address = oActiveCell.getCellAddress
activecellStr = oConv.PersistentRepresentation REM output format "Prices.B6"
addrArray = split(activecellStr,".")
targetAddr = addrArray(ubound(addrArray)) REM assign last element in address array
REM print targetAddr
wait 1000 REM this is a 1000 millisecond (1 second) pause
REM Paste special to target cell
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "ToPoint"
args7(0).Value = targetAddr
dispatcher.executeDispatch(document, ".uno:PasteOnlyValue", "", 0, Array())
End Sub
sub test
oDocument = ThisComponent 'assigns the current document to the variable document
Controller = oDocument.getcurrentController
oSheets =oDocument.Sheets
priceSheet = oSheets.getByName(“Prices”)
histSheet = oSheets.getByName(“Price History”)
oActivecell = ThisComponent.CurrentSelection
oConv = oDocument.createInstance("com.sun.star.table.CellAddressConversion")
oConv.Address = oActiveCell.getCellAddress
activecellStr = oConv.PersistentRepresentation REM output format "Prices.B6"
addrArray = split(activecellStr,".")
targetAddr = addrArray(ubound(addrArray))
print targetAddr
end sub
Thanks
Terry