+ Reply to Thread
Results 1 to 5 of 5

VBA - Show entries in ListBox2 according to selected material in ListBox1

  1. #1
    Registered User
    Join Date
    02-27-2023
    Location
    Sydney
    MS-Off Ver
    2019
    Posts
    2

    VBA - Show entries in ListBox2 according to selected material in ListBox1

    Hello,

    I´m currently facing the problem, that my VBA program doesn´t work as I wish it would. I have between 2- x materials in 'List_Mat' (Material 100520, 100620, 100658, ...) (unlimited number of materials). These materials are the raw materials of products of which some information should be shown in the listbox 'List_Into'- one raw material can be used for multiple products and therefore with the selection of one raw material, multiple material should be listed in 'List_Into'. The material numbers are saved in the table "Stammdaten" in column K. Now I would like to click on one of the raw materials in listbox 'List_Mat' and than all products which are based on the selected raw material should be shown in listbox 'List_Mat'.

    So far I have the following code:

    Dim x As Variant Dim List1Auswahl As String Dim z As Variant Dim y As Variant

    List1Auswahl = UserForm1.List_Mat.List(List_Mat.ListIndex) z = ThisWorkbook.Worksheets("Stammdaten").Columns("K:K").Find(List1Auswahl, LookIn:=xlValues).Row

    y = z Do y = y + 2 Loop While ThisWorkbook.Worksheets("Stammdaten").Cells(y, 2) = "" And Not ThisWorkbook.Worksheets("Stammdaten").Cells(y, 5) = ""

    For x = z To y If ThisWorkbook.Worksheets("Stammdaten").Cells(x, 3) <> "" Then With UserForm1.List_Into

    .ColumnCount = 4 .ColumnWidths = "100;100;100;100" .AddItem .List(List_Into.ListCount - 1, 0) = Sheets("Stammdaten").Cells(x, 1) .List(List_Into.ListCount - 1, 1) = Sheets("Stammdaten").Cells(x, 2) .List(List_Into.ListCount - 1, 2) = Sheets("Stammdaten").Cells(x, 5) .List(List_Into.ListCount - 1, 3) = Sheets("Stammdaten").Cells(x, 4)

    '.AddItem ThisWorkbook.Worksheets("Stammdaten").Cells(x, 3).Value

    End With End If Next x

    I appreciate your help.

    I´ve tried to use different codes but nothing worked so far.
    Last edited by Peet_Wackel; 02-27-2023 at 10:29 AM.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: VBA - Show entries in ListBox2 according to selected material in ListBox1

    see big yellow banner - how to upload a workbook - help us to help you - far easier for us to then give an in-context solution.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Registered User
    Join Date
    02-27-2023
    Location
    Sydney
    MS-Off Ver
    2019
    Posts
    2

    Re: VBA - Show entries in ListBox2 according to selected material in ListBox1

    Thanks a lot for your help. Please find attached the example.

    UserForm_Datenbank_light.xlsm

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: VBA - Show entries in ListBox2 according to selected material in ListBox1

    One way...

    Edit...Remove headers code snippet
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 02-28-2023 at 07:24 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: VBA - Show entries in ListBox2 according to selected material in ListBox1

    give the attached a trial - structured tables are used to contain data - with their self maintaining properties they lend themselves better for data storage - arrays are used to transfer data to and from listboxes.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Return items selected in listbox1 and not selected in listbox2
    By chris01395 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-02-2021, 10:55 AM
  2. [SOLVED] Populate Listbox2 based on value selected in ListBox1 with multiple worksheets data
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2016, 11:38 AM
  3. [SOLVED] Copy selected item from listbox1 to listbox2 unless already exists in listbox2
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2014, 07:00 PM
  4. [SOLVED] Listbox1 items to move in Listbox2.
    By siobeh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2014, 03:18 PM
  5. [SOLVED] Populate Listbox2 based on Listbox1 selection
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2013, 09:04 AM
  6. Populate Listbox2 from Listbox1 selection
    By Macro1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2010, 07:06 AM
  7. [SOLVED] Listbox1 to Listbox2?
    By Moretakitty in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-20-2005, 07:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1