Hi
I made a UserForm that collects the data from the active sheet and it copys it in to the UserForm.
In here I have a ListBox where in the options menu I set the ColumnCount: 6 becouse I have 6 rows I want to be shown in the UserForm. The Columns are A:F how many rows is actualy different. Sometime the data goes from A3:F40 and sometimes it goes from A3:F5 depends on the material order. Under options for the ListBox I tryed to enter the RowSource but I can only insert it like this A3:F40 then I have a lot of empty cells.
So is it possible somehow to insert here a dynamic range that would take cells from A3 (always the beggining cell) to F - How many rowes are filled?
Last edited by stojko89; 11-18-2011 at 02:27 AM.
Create a proper Dynamic Named Range to use as the RowSource
Alternatively, you can set the range when the form loads
Option Explicit Private Sub UserForm_Initialize() Dim rData As Range With Sheet1 '<- sheet with data on Set rData = .Range(.Cells(3, 1), .Cells(.Rows.Count, 6).End(xlUp)) End With Me.ListBox1.List = rData.Value End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
royUK
I've inserted the code like this:
And I get an error and it says that it couldn't set the Value property.Option Explicit Private Sub UserForm_Initialize() Dim rData As Range With Sheets("00057-2011") Set rData = .Range(.Cells(3, 1), .Cells(.Rows.Count, 6).End(xlUp)) End With Me.lstMaterial.Value = rData.Value End Sub
Sory!! Sory!!
I just saw I've entered the last part of the code wrong.
It works great! :D
Thanks a lot royUK!
Works for every sheet
I won't even bother to try and make the dynamic range the other way.
So thank you.
or
If you treat these sheets as data'warehouses' you can start in row 1.Private Sub UserForm_Initialize() lstMaterial.List = Sheets("00057-2011").cells(1).currentregion.offset(2).resize(,6).Value End Sub
Last edited by snb; 11-18-2011 at 02:30 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks