4

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

Newbie
  • 863
  • 1
  • 7
  • 16

2 Answers2

17

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)

Red Taz
  • 4,159
  • 4
  • 38
  • 60
Newbie
  • 863
  • 1
  • 7
  • 16
0
rem I had a similar problem to solve.
rem Update for libreoffice 7.
rem Replaced "sheet" with "ThisComponent.Sheets(0)". 
rem Thanks.


sub main 
dim cell   as object
dim i      as integer

i = 0
rem "sheet" alone does not run
cell = ThisComponent.Sheets(0).getCellByPosition(i,0) 

while Cell.Type <> com.sun.star.table.CellContentType.EMPTY
    i    = i+1
    cell = ThisComponent.Sheets(0).getCellByPosition(i,0)   
wend
MsgBox( i )
end sub 
  • While this code may solve the question, [including an explanation](https://meta.stackoverflow.com/questions/392712/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion – Muhammad Dyas Yaskur Feb 15 '21 at 00:26