Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Fill 5 Column Listbox from Range

I have a command button that I want to use to fill a 5 columned listbox in a
userform. I am getting an error: Could Not Set the List Property, why?

The first row of the listbox is a header row.

Private Sub cmbAddItem_Click()

Dim wksSource As Worksheet
Dim lngLastRow As Long
Dim i As Long

' store data storage worksheet as variable
Set wksSource = ActiveWorkbook.Sheets("Data Storage")

' find last row in ref column in data storage worksheet
lngLastRow = wksSource.Cells(Rows.Count, "A").End(xlUp).Row

With lbxPreview

' clear listbox first
.Clear

' fill listbox from temporary data storage
For i = 126 To lngLastRow
ERROR .List(.ListCount - 1, 0) = wksSource.Cells(i, 1) ' part number
.List(.ListCount - 1, 1) = wksSource.Cells(i, 2) ' part
description
.List(.ListCount - 1, 2) = wksSource.Cells(i, 3) ' unit price
.List(.ListCount - 1, 3) = wksSource.Cells(i, 4) ' qty
.List(.ListCount - 1, 4) = wksSource.Cells(i, 5) ' extended
price
Next
End With

End Sub
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Fill 5 Column Listbox from Range

Unless you have ListCount declared as a public variable somewhere, that is
probably the cause or the error. But it you have a list on a sheet, why not
just use the RowSource?

"Ryan H" wrote:

I have a command button that I want to use to fill a 5 columned listbox in a
userform. I am getting an error: Could Not Set the List Property, why?

The first row of the listbox is a header row.

Private Sub cmbAddItem_Click()

Dim wksSource As Worksheet
Dim lngLastRow As Long
Dim i As Long

' store data storage worksheet as variable
Set wksSource = ActiveWorkbook.Sheets("Data Storage")

' find last row in ref column in data storage worksheet
lngLastRow = wksSource.Cells(Rows.Count, "A").End(xlUp).Row

With lbxPreview

' clear listbox first
.Clear

' fill listbox from temporary data storage
For i = 126 To lngLastRow
ERROR .List(.ListCount - 1, 0) = wksSource.Cells(i, 1) ' part number
.List(.ListCount - 1, 1) = wksSource.Cells(i, 2) ' part
description
.List(.ListCount - 1, 2) = wksSource.Cells(i, 3) ' unit price
.List(.ListCount - 1, 3) = wksSource.Cells(i, 4) ' qty
.List(.ListCount - 1, 4) = wksSource.Cells(i, 5) ' extended
price
Next
End With

End Sub
--
Cheers,
Ryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Fill 5 Column Listbox from Range

Because I like to make things hard on myself. That is much better, thanks!
--
Cheers,
Ryan


"JLGWhiz" wrote:

Unless you have ListCount declared as a public variable somewhere, that is
probably the cause or the error. But it you have a list on a sheet, why not
just use the RowSource?

"Ryan H" wrote:

I have a command button that I want to use to fill a 5 columned listbox in a
userform. I am getting an error: Could Not Set the List Property, why?

The first row of the listbox is a header row.

Private Sub cmbAddItem_Click()

Dim wksSource As Worksheet
Dim lngLastRow As Long
Dim i As Long

' store data storage worksheet as variable
Set wksSource = ActiveWorkbook.Sheets("Data Storage")

' find last row in ref column in data storage worksheet
lngLastRow = wksSource.Cells(Rows.Count, "A").End(xlUp).Row

With lbxPreview

' clear listbox first
.Clear

' fill listbox from temporary data storage
For i = 126 To lngLastRow
ERROR .List(.ListCount - 1, 0) = wksSource.Cells(i, 1) ' part number
.List(.ListCount - 1, 1) = wksSource.Cells(i, 2) ' part
description
.List(.ListCount - 1, 2) = wksSource.Cells(i, 3) ' unit price
.List(.ListCount - 1, 3) = wksSource.Cells(i, 4) ' qty
.List(.ListCount - 1, 4) = wksSource.Cells(i, 5) ' extended
price
Next
End With

End Sub
--
Cheers,
Ryan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
range as listbox column BigPig Excel Programming 3 January 25th 08 03:22 PM
Fill a multicolumn listbox with data from a range in another works Dale Fye Excel Programming 1 October 12th 07 06:58 PM
populate 2 column listbox from one named range Jacob Excel Programming 4 November 5th 06 02:51 AM
ListBox "dynamic fill range" TK Excel Programming 3 September 10th 04 07:07 AM
Fill a listbox with data from variable range Al Excel Programming 2 August 10th 04 07:05 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"