For what the MATCH() calls if you already know you want to include columns up to H (A7:H7)?
Well. I don't know anything about Excel-VBA, and the code you posted surely was recorded without much of considerations.
Insisting on doing such a strange thing by "macro" in AOO, and the question from the first line above aside, you may use the following code:
Code: Select all
Sub sameInAoo_BasicAndApi() REM Avoiding strange detours
doc = ThisComponent
currC = doc.CurrentController
sheet = currC.ActiveSheet REM Doubtable! Why not get the sheet by its name?
ultC = 1023 REM Column index 0-based
endR = 100 REM Row index 0-based
lookupRg = sheet.GetCellRangeByPosition(0, 5, ultC, 5)
REM That's A6:AMJ6 (aka 6:6 in full-row-syntax).
lookupDA = lookupRg.getDataArray
findStr = "ÜCRETLİ GÜN TOP."
For c=0 To ultC REM This works instead of the doubled MATCH calls
REM in the original Sub without formula hokum.
If lookupDA(0)(c)=findStr Then Exit For
Next c
If c>ultC Then
Print "No match!" REM Find a better Exit!
Exit Sub
End If
rgToFill = sheet.getCellRangeByPosition(0, 6, c, endR)
contCell = sheet.getCellRangeByName("B6")
sheet.Unprotect("8453")
rgToFill.fillAuto(0, 1) REM Assuming that's what MS Excel AutoFill does. You may need
REM rgToFill.fillSeries(0, 0, 0, 0, 0) (constant series).
currC.select(contCell)
sheet.protect("8453")
End Sub
It looks longer, but is basically clearer, and it avoids the intricate usage of a Calc formula.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München