+ Reply to Thread
Results 1 to 6 of 6

How to match data from worksheet and show it in ListBox?

  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    pakistan
    MS-Off Ver
    Excel 2007
    Posts
    89

    How to match data from worksheet and show it in ListBox?

    Hello EveryOne!

    I have a userform with two combo boxes and a ListBox.

    The userform brings the data from “Sheet1” and display it in userform ListBox1 by matching ComboBox1 and Combox2 requirments.

    ComboBox1 is working ok. ComboBox1 match its data from Coloumn 1 of Sheet1.

    The data for ComboBox2 to match is in column 3 and 4 of Sheet1.

    For example.

    In the Userform if I select year “2014” and item “ Laptop”. It just display data of “Line 2”and “Line 5” (It just look at column 3 of Sheet1)

    But It should also show the data of “Line 3” and “Line 4” of Sheet1 as well because Item “Laptop” is also there .It should also look at column 4 of Sheet 1 as well.

    So how from coding I can edit the following line so that ComboBox2 should look both in Field 3 and 4 of Sheet 1.

    .Range("A1:D" & LastRow).AutoFilter Field:=3, Criteria1:=Me.ComboBox2.Value


    I have attched userform as well.

    I would be very thankful for your help guys.

    Best Regards
    z-eighty2
    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: How to match data from worksheet and show it in ListBox?

    Hi replace your combobox 2 Code with below one

    i just make slight changes
    Please Login or Register  to view this content.
    Last edited by Naveed Raza; 07-09-2014 at 12:40 AM.
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Registered User
    Join Date
    02-22-2013
    Location
    pakistan
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: How to match data from worksheet and show it in ListBox?

    Hi,

    Thanks "Naveed Raza" for your help.Your code is working perfect as I want.

    One more little help please how the following code line will be change if I have 2 more columns in
    Sheet1. (e.g Sales in Region 3 and Sales in Region 4). How the code will look if I add two more columns to filter?

    For j = 1 To 2

    .Range("A1:D" & LastRow).AutoFilter Field:=j + 2, Criteria1:=Me.ComboBox2.Value

    Thanks,

    Kind Regards
    z-eighty2

  4. #4
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: How to match data from worksheet and show it in ListBox?

    Just replace 2 with that number suppose if u add 2 more columns then change 2 to 4

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-22-2013
    Location
    pakistan
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: How to match data from worksheet and show it in ListBox?

    Hi Naveed Raza,

    I tried to change the code from " 1 to 4 " but it does not work and give error?
    Any idea?

    Regards
    z-eighty2

  6. #6
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: How to match data from worksheet and show it in ListBox?

    if you have change 2 to 4 then you must have to change the next two line as well to filter that value

    this is our previous code for 2
    Please Login or Register  to view this content.
    now in below code i change 2 to 4
    Please Login or Register  to view this content.
    so if your changing the value then at the same time u have to change the column name as well

+ 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] Want to show name without duplicates Using FIlter Data Using ListBox
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2014, 01:50 AM
  2. [SOLVED] How to show data in UserForm ListBox from WorkSheet?
    By z-eighty2 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-31-2014, 05:26 PM
  3. [SOLVED] first item in listbox does not show in listbox
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2013, 10:33 AM
  4. [SOLVED] Show data from textbox in a listbox using VBA
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2013, 11:04 AM
  5. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM

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