Copy Paste Data Range From Another Worksheet

Wondering if there’s a way to translate this excel vba code to LO.

It’s suppose to copy a data range from one sheet, select a 2nd sheet, find the last row of data on the 2nd sheet and paste the data from sheet 1.

Sub copyData()

Sheets("Data").Select
lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Range("A2:F" & lr).Copy
Sheets("Target Book").Select
lrTarget = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Cells(lrTarget + 1, 1,).Select
ActiveSheet.Paste
Columns("A:F").AutoFit

End Sub

1 Like

In this office, it is recorded a little differently:

Sub copyRangeToAnotherSheet
Dim oSheets As Variant
Dim oSheet As Variant
Dim oCursor As Variant
Dim aRangeAddress As New com.sun.star.table.CellRangeAddress ' What to copy '
Dim aCellAddress As New com.sun.star.table.CellAddress ' Where copy '
	oSheets = ThisComponent.getSheets()
	oSheet = oSheets.getByName("Data")	' Source sheet '
	oCursor = oSheet.createCursor(): oCursor.gotoEndOfUsedArea(True)
	aRangeAddress = oCursor.getRangeAddress()
	If aRangeAddress.EndRow > 0 Then ' There is data starting from the second row '
		aRangeAddress.StartRow = 1
		oSheet = oSheets.getByName("Target Book") ' Target sheet '
		oCursor = oSheet.createCursor(): oCursor.gotoEndOfUsedArea(True) ' Find last used row '
		aCellAddress = oSheet.getCellByPosition(0, oCursor.getRangeAddress().EndRow + 1).getCellAddress()
		oSheet.copyRange(aCellAddress, aRangeAddress)	' Copy - without copy to clipboard and paste '
		oCursor.getColumns().OptimalWidth = True ' AutoFit '
	Endif
End Sub

Perfect! Exactly what I was looking for! Thank you so much!