Specified Listbox Value

kayza

Board Regular
Joined
Apr 29, 2015
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I have problems in determining the content of the ListBox, where I wanted the contents of the listbox only containing the values according to the specified criteria. here is the example data

AB
1oneOK
2two-
3threeOK
4fourOK
5five-

<tbody>
</tbody>

from the above example, I would like to make ListBox only displays if the values in column "B" is "-". so the ListBox values should be like this :

two-
five-

<tbody>
</tbody>

Is it possible to displays the Listbox value only from the specified criteria ?

I really appreciate for all the assistance provided
Thanks.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Assuming that the sheet containing the data is the active sheet, try...

Code:
[COLOR=darkblue]Dim[/COLOR] vData [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
[COLOR=darkblue]Dim[/COLOR] i [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]

vData = Range("A1:B" & Cells(Rows.Count, "A").End(xlUp).Row)

[COLOR=darkblue]For[/COLOR] i = 1 [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](vData)
    [COLOR=darkblue]If[/COLOR] vData(i, 2) = "-" [COLOR=darkblue]Then[/COLOR]
        [COLOR=darkblue]With[/COLOR] Me.ListBox1
            .AddItem vData(i, 1)
            .List(.ListCount - 1, 1) = vData(i, 2)
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Next[/COLOR] i

Change the name of the ListBox, accordingly.

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,216,159
Messages
6,129,210
Members
449,493
Latest member
JablesFTW

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