Ask Your Question

listbox create

asked 2018-07-26 05:10:37 +0200

joaorochaj gravatar image

updated 2018-07-28 05:06:06 +0200

I want to make a list box that receives "a1: b10" from the "report" worksheet and shows the two columns in the list box, I'm trying with the code below

    Dim oDialogo3 As Object
   Dim vListBox As Object

Sub AtualizaListBox

Dim oSheet As Object
Dim oRange As Object
Dim i As Integer
Dim s As String

vListBox = oDialogo3.GetControl("ListBox1")

oSheet = ThisComponent.Sheets.getByName("RELATORIO")
oRange = oSheet.getCellRangeByName("A1:B10").RangeAddress

If vListBox.ItemCount > 0 Then vListBox.removeItems(0, vListBox.ItemCount)

For i = 0 To oRange.EndRow - oRange.StartRow
    s = oSheet.getCellByPosition(oRange.StartColumn, oRange.StartRow + i).String
    vListBox.addItem(s, i)
Next i

End Sub

edit retag flag offensive close merge delete


Hello @joaorochaj

I believe a bit of information may help here. Is the listbox on a form or a dialog (don't see loading dialog or form access)? How is the code run? If you are wanting data from a1:b10 why are you getting cell range a1:a300? Will the list box then result in 20 entries a1-a10 then b1-b20? What is AtualizaListBox2 & AtualizaListBox3?

Ratslinger gravatar imageRatslinger ( 2018-07-26 06:12:10 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-07-28 16:29:18 +0200

Ratslinger gravatar image


Please see answers in this post -> Filling combobox in userform with range in spreadsheet.

Your code is missing some information which you haven't provided (asked for in comment). The referred to post shows code using a dialog - your code seems to refer to a dialog but neither loads that nor accesses a form if you are not using a dialog.

The referred to post has another answer which, if using a form, displays how code is really unnecessary and can fill directly from the cells.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-07-26 05:10:37 +0200

Seen: 232 times

Last updated: Jul 28 '18