Hi!
I work in a LibreOffice Macro. My code work so slowly because of my data. I have around 10,000 data in a sheet and when I write for loop and if statement, my code work is so slowly(It works about 5hours). Is there any methods to run it rapidly?
I added my code that works slowly.
Sub Main
rA = CreateUnoStruct("com.sun.star.table.CellRangeAddress")
cA = CreateUnoStruct("com.sun.star.table.CellAddress")
aaA = CreateUnoStruct("com.sun.star.table.CellRangeAddress")
abA = CreateUnoStruct("com.sun.star.table.CellAddress")
acA = CreateUnoStruct("com.sun.star.table.CellRangeAddress")
adA = CreateUnoStruct("com.sun.star.table.CellAddress")
aeA = CreateUnoStruct("com.sun.star.table.CellRangeAddress")
afA = CreateUnoStruct("com.sun.star.table.CellAddress")
'Sheet 2 'Ürün Ağaçları(Sheet Name)
Doc = ThisComponent
Sheeti2 = Doc.Sheets.getByIndex(2)
Curs = Sheeti2.createCursor
Curs.gotoEndOfUsedArea(True)
NumRows2 = Curs.Rows.Count
'Sheet 5 '3 Aylık Pivot(Sheet Name)
Doc = ThisComponent
Sheeti5 = Doc.Sheets.getByIndex(5)
Curs = Sheeti5.createCursor
Curs.gotoEndOfUsedArea(True)
NumRows5 = Curs.Rows.Count
dim document as object
document = ThisComponent
sheet1 = document.Sheets(5)'3 Aylık Pivot(Sheet Name)
sheet2 = document.Sheets(2)'Ürün Ağaçları(Sheet Name)
sheet3 = document.Sheets(6)'3 Aylık Tahmin(Sheet Name)
sheet4 = document.Sheets(7)'Ağaçla Tahminler(Sheet Name)
sheet5 = document.Sheets(3)'Takım Ağaçları (Sheet Name)
For iCountTree = 0 to NumRows5 '3 Aylık pivottaki satır sayısı
For iCountTree1 = 1 to NumRows2'ürün ağacı satır sayısı
if sheet1.getCellByPosition(0, iCountTree+5).String = sheet2.getCellByPosition(1, iCountTree1).String Then
'Parça Kodunu copy start
With aaA
.Sheet = 2
.StartColumn = 2
.StartRow = iCountTree1
.EndColumn = 2
.EndRow = iCountTree1
End With
'Parça Kodunu copy finish
'Ürün Kodu copy start
With acA
.Sheet = 2
.StartColumn = 1
.StartRow = iCountTree1
.EndColumn = 1
.EndRow = iCountTree1
End With
'Ürün Kodu copy finish
'Parça Miktarını copy start
With aeA
.Sheet = 2
.StartColumn = 4
.StartRow = iCountTree1
.EndColumn = 4
.EndRow = iCountTree1
End With
'Parça Miktarını copy finish
for iCountForEmpty = 1 to NumRows2*2'Bu Sayıyı Ağaçların listesinden fazla olacak şekilde seçtim
if sheet4.getCellByPosition(1, iCountForEmpty).String = empty then
'Parça Kodunu paste start
With abA
.Sheet = 7
.Column = 2
.Row = iCountForEmpty
End With
ThisComponent.Sheets(7).CopyRange(abA, aaA)
'Parça Kodunu paste finish
'Ürün Kodu paste start
With adA
.Sheet = 7
.Column = 1
.Row = iCountForEmpty
End With
ThisComponent.Sheets(7).CopyRange(adA, acA)
'Ürün Kodu paste finish
'Parça Miktarını paste start
With afA
.Sheet = 7
.Column = 3
.Row = iCountForEmpty
End With
ThisComponent.Sheets(7).CopyRange(afA, aeA)
'Parça Miktarını paste finish
'For to be empty to value of cells start
'Parça Kodunu copy start
With aaA
.Sheet = 2
.StartColumn = 15
.StartRow = 1
.EndColumn = 15
.EndRow = 1
End With
'Parça Kodunu copy finish
'Ürün Kodu copy start
With acA
.Sheet = 2
.StartColumn = 15
.StartRow = 1
.EndColumn = 15
.EndRow = 1
End With
'Ürün Kodu copy finish
'Parça Miktarını copy start
With aeA
.Sheet = 2
.StartColumn = 15
.StartRow = 1
.EndColumn = 15
.EndRow = 1
End With
'Parça Miktarını copy finish
'For to be empty to value of cells finish
Exit For
else
end if
next iCountForEmpty
Else
end if
next iCountTree1
next iCountTree
End Sub
Edit for @JohnSUN: