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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

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?
 

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.
 

Nick147

Board Regular
Joined
Apr 24, 2003
Messages
111
It shouldn't be a problem this time, but thank you for the additional information.

NL
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,491
Messages
5,764,676
Members
425,229
Latest member
Rashid mahmood

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