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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,022
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

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,022
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,186,808
Messages
5,959,926
Members
438,454
Latest member
leopedrini

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
Top