Populate listbox on userform from another workbook

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,596
Office Version
  1. 2007
Platform
  1. Windows
I have a userform which has a Listbox.
I would like to populate this Listbox with customers names another workbook.
The selected Listbox name would then be placed in Textbox1

Some info for you for the external workbox etc

Workbook is called DR
Worksheet in question is called POSTAGE
Customers names are in column B
The population wouldnt need to list ALL from column B but say last row & up 10 rows
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
UPDATE
I should of said COMBOBOX not LISTBOX

So now i have this code in use but please can you advise how i have it from last row up for column B

VBA Code:
With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
ComboBox1.List = .Sheets("POSTAGE").Range("B100:B150").Value
.Close 0
End With
 
Upvote 0
With the following i get the RTE message Could not set the list property.

VBA Code:
With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
ComboBox1.List = .Sheets("POSTAGE").Cells(Rows.Count, 1).End(xlUp).Row

.Close 0
End With
 
Upvote 0
Without knowing exactly how Comboboxes work, what happens if you change to this? It grabs the last row with values in col B and the 10 rows above it (untested code)
VBA Code:
With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
set s = .Sheets("POSTAGE")
Set b2 = s.Cells(Range("B" & Rows.Count).End(xlUp).Row, "B")
Set b1 = b2.Offset(-10, 0)
ComboBox1.List = s.Range(b1, b2)
.Close 0
End With
 
Upvote 0
Hi,
I have applied that but get variable not defind.
set s line of code is highlighted
I assume it will do the same for the next two.

Not sure how or what to write to define it
 
Upvote 0
Does this fix it?
VBA Code:
With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
Dim s As Worksheet, b1 As Range, b2 As Range
Set s = .Sheets("POSTAGE")
Set b2 = s.Cells(Range("B" & Rows.Count).End(xlUp).Row, "B")
Set b1 = b2.Offset(-10, 0)
ComboBox1.List = s.Range(b1, b2)
.Close 0
End With
 
Upvote 0
Hi,
I haveapplied that but now i get COULD NOT SET THE LIST PROPERTY, INVALID PROPERTY ARRAY INDEX
The issue is the line of code in Red shown below

Rich (BB code):
With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
Dim s As Worksheet, b1 As Range, b2 As Range
Set s = .Sheets("POSTAGE")
Set b2 = s.Cells(Range("B" & Rows.Count).End(xlUp).Row, "B")
Set b1 = b2.Offset(-10, 0)
ComboBox1.List = s.Range(b1, b2)
.Close 0
End With
 
Upvote 0
I tested it and got the same error, adding .Value after the range fixes it:
Rich (BB code):
With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
Dim s As Worksheet, b1 As Range, b2 As Range
Set s = .Sheets("POSTAGE")
Set b2 = s.Cells(Range("B" & Rows.Count).End(xlUp).Row, "B")
Set b1 = b2.Offset(-10, 0)
ComboBox1.List = s.Range(b1, b2).Value
.Close 0
End With
 
Upvote 0
That got past the error but it doesnt work as it should for me.
This is the code i have in use.

VBA Code:
    With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
        Dim s As Worksheet, b1 As Range, b2 As Range
        Set s = .Sheets("POSTAGE")
        Set b2 = s.Cells(Range("B" & Rows.Count).End(xlUp).Row, "B")
        Set b1 = b2.Offset(-10, 0)
        ComboBox1.List = s.Range(b1, b2).Value
       .Close 0
End With

On my worksheet i am currently at row 2207 BUT when i look at the 10 customers values the code has put in the ComboBox its row 603 & then 9 others.
This is way back up my list & not the last 10
 
Upvote 0
Ye, I didn't think to actually test with two different files as you have, found the issue.
VBA Code:
With GetObject("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
        Dim s As Worksheet, b1 As Range, b2 As Range
        Set s = .Sheets("POSTAGE")
        Set b2 = s.Cells(s.Range("B" & s.UsedRange.Rows.Count + 1).End(xlUp).Row, "B")
        Set b1 = b2.Offset(-10, 0)
        ComboBox1.List = s.Range(b1, b2).Value
       .Close 0
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top