Libreoffice calc: loop throught cells macro

Newbie picture Newbie · Oct 25, 2013 · Viewed 19.3k times · Source

I've been searching a lot but could find little to no info about LibreOffice Basic

I'm a bit used to programming macros in excel but this time a need to do a loop until i reach the first empty column and it needs to be in libreoffice.

In excel i would do something like this:

Dim i As integer

i = 0
Range("A1").Select
While cell.Offset(0, i).Value <> Null
    i = i + 1
Wend
MsgBox ("First empty column is " & Chr(i + 64))

But in libreoffice i have no idea.

Can anyone help me.

Thanks, Bruno

Answer

Newbie picture Newbie · Oct 26, 2013

I managed to find the answer this way:

dim cell as object
dim i as integer

i = 0
cell = Sheet.getCellByPosition(i,0)

while Cell.Type <> com.sun.star.table.CellContentType.EMPTY
    i = i+1
    cell = Sheet.getCellByPosition(i,0)
wend

When the loop ends I get the variable i which corresponds to the column number. I can then convert it to the letter the same way as in excel (chr functions)