Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting SpreadSheet rows into UserForm Listbox?

Status
Not open for further replies.

logius

Programmer
Aug 30, 2001
175
US
Is it possible to insert groups of rows into a ListBox on a UserForm through VBA? The AddItem method doesn't seem be the right way to go for this.

Any assistance would be greatly appreciated.

----------------------------------------
If you are reading this, then you have read too far... :p
 


Hi,

The ListFillRange can be referenced by Sheet and column range
[tt]
Sheet1!A2:A10
[/tt]
I perfer using Named Ranges and then referening the Range Name in the ListFillRange box.

How can I rename a table as it changes size faq68-1331

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
There is no ListFillRange property for a UserForm ListBox. The RowSource is the closest thing.

----------------------------------------
If you are reading this, then you have read too far... :p
 


Same thing.

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
The only problem is the RowSource will only allow a single range to be set. I tried using a disjointed NamedRange to simulate what I'll need, but it didn't work (although it didn't give an error the list remained blank).

What I need is a routine to add in lines to the ListBox based on the results of an active search. The goal is to have something similar to the layout of the Search function in the Windows' Start Menu.

----------------------------------------
If you are reading this, then you have read too far... :p
 


AddItem will work. A non-contigulus range referenc will not.

Where is your code that did not work?

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
ActiveWorkbook.Names.Add Name:="NamedRange", RefersToR1C1:= _
"='Full Data'!R2,'Full Data'!R4,'Full Data'!R6, _
'Full Data'!R10,'Full Data'!R14,'Full Data'!R18, _
'Full Data'!R21"

Form2.ListBox1.RowSource = ActiveWorkbook.Names("NamedRange")


----------------------------------------
If you are reading this, then you have read too far... :p
 


That will not work.

What about the AddItem code that you earlier said did not work?

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
The row I want to add in is sent to a seperate procedure via a variable value (RwIdx).

Code:
Sub SrchResult(RwIdx As Integer)

   frmResults.lbxResult.AddItem (ActiveSheet.Rows(RwIdx))

End Sub

SrchResult is called each time an item in the spreadsheet meets the criteria of the search. I've even tried hardcoding multiple calls to the procedure using various RwIdx values, but I keep getting a Type-Mismatch error on that line.

----------------------------------------
If you are reading this, then you have read too far... :p
 
I really don't think the AddItem method of an UserForm.ListBox admits a Range object as argument ...
When the cursor is inside the word AddItem in your code feel free to press the F1 key to get more info on this method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 


ActiveSheet.Rows(RwIdx) returns a ROW

You want a VALUE.

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 


ActiveSheet.Rows(RwIdx) returns a ROW

You need a VALUE.

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top