Hello Friends,
Can any one help me ?.
i can get results While running VBA macro in Excel. Using “Do Util and IF Condition” and copy the data and paste in respective Sheetnames (FilmRating) one by one.
But, In LibreOffice i Can’t get the results, Like VBA does.
I tried both method ->>>> 1 ) setDataArray() and getDataArray()
2) copyRange(cellAddress, RangeAddress)
Can any one tell me where i made mistake? and how to get the results in BASIC macros in LibreOffice
Both method 1) & 2) I want Proper Code.
I have attached the Source Files. Both->>> Excel and Calc Spreadsheets
Source Data
Excel File
Do Until and Do While Loops.xlsx (13.9 KB)
Excel Macro Code
Sub ProfessionalWay_SeperatingListWith_DoLoop()
Dim FilmLength As Integer
Dim FilmRating As String
Application.ScreenUpdating = False
Worksheets("Sheet1").Activate
Range("A3").Select
Do Until ActiveCell.Value = ""
FilmLength = ActiveCell.Offset(0, 3).Value
If FilmLength < 100 Then
FilmRating = "Short"
ElseIf FilmLength < 120 Then
FilmRating = "Medium"
ElseIf FilmLength < 150 Then
FilmRating = "Long"
Else
FilmRating = "Epic"
End If
Range(ActiveCell, ActiveCell.End(xlToRight)).Copy
Worksheets(FilmRating).Select
ActiveCell.PasteSpecial
ActiveCell.Offset(1, 0).Select
Worksheets("Sheet1").Activate
ActiveCell.Offset(1, 0).Select
Loop
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Screen Shots Of _Excel Macro Result

Part 15 - Do Until and Do While Loops_CopyRange.ods (15.5 KB)
LibreOffice BASIC Macro Code _Method1_Using getDataArray & setDataArray
Sub SeperatingListWith_DoLoop_set_get_DataArra()
Dim Doc As Object, oSheets As Object, Sheet As Object
Dim Cell As Object, oCell As Object, CopyRange As Object, PasteRange As Object
Dim CopyData()
Dim i As Integer
Dim FilmLength As Integer
Dim FilmRating As String
Doc = ThisComponent : oSheets = Doc.Sheets(0)
Doc.CurrentController.setActiveSheet(oSheets)
Cell = oSheets.getCellByPosition(0, 2) ' A3
i = 0
Do Until Cell.Type = com.sun.star.table.CellContentType.EMPTY ' Cell.getType(com.sun.star.table.CellContentType.EMPTY)
FilmLength = oSheets.getCellByPosition(3, i+2).getValue()
If FilmLength < 100 Then
FilmRating = "Short"
ElseIf FilmLength < 120 Then
FilmRating = "Medium"
ElseIf FilmLength < 150 Then
FilmRating = "Long"
Else
FilmRating = "Epic"
End If
CopyRange = oSheets.getCellRangeByPosition(0, i+2, 3, i+2)
CopyData = CopyRange.getDataArray()
Sheet = Doc.getSheets().getByName(FilmRating)
Doc.CurrentController.setActiveSheet(Sheet)
PasteRange = Sheet.getCellRangeByPosition(0, i, 3, i)
PasteRange.setDataArray(CopyData)
Doc.CurrentController.setActiveSheet(oSheets)
Cell = oSheets.getCellByPosition(0, 2+i)
i = i + 1
Loop
End Sub
Macro Result Screen Shots
LibreOffice BASIC Macro _Using_copyRange()_Method 2
Sub SeperatingListWith_DoLoop_copyRange()
Dim Doc As Object, oSheets As Object, Sheet As Object
Dim Cell As Object, oCellAddress As Object, CopyRange As Object, PasteRange As Object
Dim CopyData()
Dim i As Integer
Dim FilmLength As Integer
Dim FilmRating As String
Doc = ThisComponent : oSheets = Doc.Sheets(0)
Doc.CurrentController.setActiveSheet(oSheets)
Cell = oSheets.getCellByPosition(0, 2) ' A3
i = 0
Do Until Cell.Type = com.sun.star.table.CellContentType.EMPTY ' Cell.getType(com.sun.star.table.CellContentType.EMPTY)
FilmLength = oSheets.getCellByPosition(3, i+2).getValue()
If FilmLength < 100 Then
FilmRating = "Short"
ElseIf FilmLength < 120 Then
FilmRating = "Medium"
ElseIf FilmLength < 150 Then
FilmRating = "Long"
Else
FilmRating = "Epic"
End If
CopyRange = oSheets.getCellRangeByPosition(0, i+2, 3, i+2).getRangeAddress()
Sheet = Doc.Sheets.getByName(FilmRating)
Doc.CurrentController.setActiveSheet(Sheet)
oCellAddress = Sheet.getCellByPosition(0,0).getCellAddress()
CopyRange.StartColumn = 0
CopyRange.EndColumn = 3
oSheets.copyRange(oCellAddress, CopyRange)
oCellAddress.Row = oCellAddress.Row + 1
Doc.CurrentController.setActiveSheet(oSheets)
Cell = oSheets.getCellByPosition(0, 2+i)
i = i + 1
Loop
End Sub
Macro Result _Screen Shots