Userform - listbox don`t work with a named selection

otrava18

Board Regular
Joined
Feb 11, 2018
Messages
61
Hello all,

I have an issue with a List box. I want to show a selection cells and i have an issue. I select cells and i gave them a name (i can see it in name manager). I set in the RowSource and i set also on a button (see the bottom code) but when i press the button "show data" nothing is happening. If i set a range in my code "A50:R105" is working. If my named selection is "A50:B105" is also working (maybe because the columns are consecutive). But in my desire selection i remove some columns which i don`t want to show. Is there a possibility to show from my selection only rows where on column "O" is <> 0 ?

VBA Code:
Private Sub CommandButton1_Click()
ListBox1.ColumnCount = 13
ListBox1.RowSource = "Detalii"
End Sub

ListBox.png

Thank you !
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
It should be
VBA Code:
ListBox1.RowSource = Range("Detalii")
The way that you had it, "Detalii" was a text string, not a range.
 
Upvote 0
It should be
VBA Code:
ListBox1.RowSource = Range("Detalii")
The way that you had it, "Detalii" was a text string, not a range.

I tried like you said and i receive error. And debug show me that line. Run-time error '13' : Type mismatch.
 
Upvote 0
The listbox has to have 18 columns. Set the columns you don't want to show to 0(zero) wide
 
Upvote 0
I tried like you said and i receive error. And debug show me that line. Run-time error '13' : Type mismatch.
If Range("A50:R105") works then Range("Detalii") will also work if it is defined as referring to =A50:R115
If the named range is causing an error when the normal range works fine then that would mean that you have not defined the named range correctly.

Although I did miss the fact that you want to show rows based on criteria, which you would not be able to do directly from a range anyway, to do that you need to loop through the range using AddItem.
 
Upvote 0

Forum statistics

Threads
1,215,850
Messages
6,127,282
Members
449,373
Latest member
jesus_eca

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