vba listbox value matches list

CelineT

I have a user form where they should pick a supplier from a table in the worksheet and when they press the "ShowProducts" command, the form should show all the articles from this supplier in the textbox below.

I made the following code but it keeps giving me an error on the line If Suppl.Value = Me.LstB_Supplier.Value Then.

I have searched and tried different options I have found on this and other sites, but I can't seem to find what it wrong.

Can anyone help me out? Thanks!

Private Sub Cmd_ShowProducts_Click()

    Dim Suppl As Range
    Dim i As Integer

    For Each Suppl In Range("T_Prod_Fix[Supplier Name]")
        If Suppl.Value = Me.LstB_Supplier.Value Then
             With Me.LstB_Products
                 .AddItem
                 .List(i, 0) = Suppl.Offset(0, 1).Value   'article nbr
                 .List(i, 1) = Suppl.Offset(0, -1).Value  'article name
                 i = i + 1
             End With
          End If
     Next Suppl

End Sub
Vityata

If you need to check, whether a value, selected in a list box is present in another list, you need a nested loop. With the first loop you get the selected value and with the inner loop you need to check whether it exists in your range.

E.g. in your case:

For lItem = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(lItem) Then 'Check for selection
        For Each suppl In Range("T_Prod_Fix[Supplier Name]")
            If suppl = ListBox1(lItem) Then
                'your logic
            End If
        Next suppl
    End If
Next lItem

Related: VBA to get values from a listbox on a spreadsheet in Excel

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Access 2010 VBA how to check value of a listbox

From Dev

VBA listbox copy to listbox

From Dev

VBA listbox copy to listbox

From Dev

Excel VBA: Searching for value in listbox based on value set in textbox

From Dev

VBA EXCEL: Use value in Listbox as Lookup value in the Match WorksheetFunction

From Dev

Excel VBA: Searching for value in listbox based on value set in textbox

From Dev

Select a value in Listbox and set focus over that value - VBA

From Dev

VBA - determine if a cell value (String) matches a Value (String) in a named range

From Dev

VBA - determine if a cell value (String) matches a Value (String) in a named range

From Dev

List Picker selected value and listbox selected value in Windows Phone

From Dev

creating a new dataframe based off if a particular value matches a value in a list

From Dev

VBA Check if Value is in the list with condition

From Dev

Programmatically select items in listbox with value's from list

From Dev

VBA listbox issue

From Dev

Excel VBA Listbox links

From Dev

VBA search through listbox

From Dev

VBA Listbox and loop

From Dev

VBA Listbox Drag & Drop

From Dev

VBA listbox issue

From Dev

Excel VBA Listbox links

From Dev

Listbox excel vba

From Dev

VBA - Adding a listbox to an array

From Dev

VBA - ListBox cannot populate

From Dev

Check a list of checkboxes if input value matches one of the values in different array

From Dev

Check a list of checkboxes if input value matches one of the values in different array

From Dev

Check if an Item's Property's value matches any from a list

From Dev

Assert parameter to stubbed function matches at least 1 value from a list?

From Dev

Copy a link if cell value matches entry in another list

From Dev

Iterate Over a list, deleting every value that matches a database

Related Related

  1. 1

    Access 2010 VBA how to check value of a listbox

  2. 2

    VBA listbox copy to listbox

  3. 3

    VBA listbox copy to listbox

  4. 4

    Excel VBA: Searching for value in listbox based on value set in textbox

  5. 5

    VBA EXCEL: Use value in Listbox as Lookup value in the Match WorksheetFunction

  6. 6

    Excel VBA: Searching for value in listbox based on value set in textbox

  7. 7

    Select a value in Listbox and set focus over that value - VBA

  8. 8

    VBA - determine if a cell value (String) matches a Value (String) in a named range

  9. 9

    VBA - determine if a cell value (String) matches a Value (String) in a named range

  10. 10

    List Picker selected value and listbox selected value in Windows Phone

  11. 11

    creating a new dataframe based off if a particular value matches a value in a list

  12. 12

    VBA Check if Value is in the list with condition

  13. 13

    Programmatically select items in listbox with value's from list

  14. 14

    VBA listbox issue

  15. 15

    Excel VBA Listbox links

  16. 16

    VBA search through listbox

  17. 17

    VBA Listbox and loop

  18. 18

    VBA Listbox Drag & Drop

  19. 19

    VBA listbox issue

  20. 20

    Excel VBA Listbox links

  21. 21

    Listbox excel vba

  22. 22

    VBA - Adding a listbox to an array

  23. 23

    VBA - ListBox cannot populate

  24. 24

    Check a list of checkboxes if input value matches one of the values in different array

  25. 25

    Check a list of checkboxes if input value matches one of the values in different array

  26. 26

    Check if an Item's Property's value matches any from a list

  27. 27

    Assert parameter to stubbed function matches at least 1 value from a list?

  28. 28

    Copy a link if cell value matches entry in another list

  29. 29

    Iterate Over a list, deleting every value that matches a database

HotTag

Archive