Listbox Problem

Nick147

Board Regular
Joined
Apr 24, 2003
Messages
111
Below is my code for listbox. My problem is that the listbox pulls information from the activesheet not the "CreditData" sheet. What is wrong with my code?

colcnt = Worksheets("CreditData").UsedRange.Columns.Count
rowcnt = Worksheets("CreditData").UsedRange.Rows.Count
Set rng = Worksheets("CreditData").Rows("2:" & rowcnt)
With ListBox2
.ColumnCount = 5
.RowSource = rng.Address
cw = ""
For c = 1 To .ColumnCount
cw = cw & rng.Columns(c).Width & ";"
Next c
.ColumnWidths = cw
.ListIndex = 0
End With


NL
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
It's because rng.Address is not returning more specific information. Try setting the External arg to true.

.RowSource = rng.Address(External:=True)

Does that fix it?
 
Upvote 0
One footnote: the External address also adds in the workbook name. If the workbook name will vary, you might keep that in mind as a possible issue. If it causes problems, you may want to re-work the code to clip off the WB name from the address before assigning it to the .RowSource property.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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