ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error populating a list box (https://www.excelbanter.com/excel-programming/444740-error-populating-list-box.html)

PA[_2_]

Error populating a list box
 
Hi,
I am running the code below to populate a list box and I suddenly I start getting the error. This same code used to work and I the error is in the line ".ListIndex = 3" (regardless the value, the list box has 10 items). If I delete this line, everything works fine.

Any ideas?

Thanks in advance.

---------------------------
Microsoft Visual Basic
---------------------------
Run-time error '91':

Object variable or With block variable not set
---------------------------
OK Help
---------------------------



Private Sub UserForm_Initialize()
Dim lbtarget As MSForms.ListBox
Dim ws As Worksheet
Dim rngSource As Range
Dim count As Integer
Set ws = ActiveWorkbook.Sheets("Utilizadores")
count = Application.count(Range(ws.Cells(2, 1), ws.Cells(200, 1)))
Set rngSource = Range(ws.Cells(2, 1), ws.Cells(count + 1, 2))
Set lbtarget = Me.listbox1
With Me.listbox1
.Clear
.ColumnCount = 2
.ColumnWidths = "20;280"
.List = rngSource.Cells.Value
.ListIndex = 3
End With
End Sub

isabelle

Error populating a list box
 
hi,

..List = ws.rngSource.Cells.Value


--
isabelle


Le 2011-07-05 03:34, PA a écrit :
.List = rngSource.Cells.Value



All times are GMT +1. The time now is 07:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com