+ Reply to Thread
Results 1 to 10 of 10

loop through values in listbox and search for them in excel sheet

  1. #1
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    loop through values in listbox and search for them in excel sheet

    Hi! PLEASE help! I've been stuck on this for days...

    I have a listbox with several values in them. The listbox gets those values from row1 of my sheet. When I click a button, I need for the code to loop through the listbox, and search for each value in Sheet1 (which will always be in Row1), and I need it to select the entire column where that value is located.

    For example, I have values a, b, and c in the listbox. Upon clicking a button, I need for it to go search Sheet1, find where values a, b, and c are located in Row1 of Sheet1, and I need it to select the entire column and copy that column.


    All help is extremely appreciated.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: loop through values in listbox and search for them in excel sheet

    How are the values added to the ListBox? A sample workbook would help
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: loop through values in listbox and search for them in excel sheet

    Please Login or Register  to view this content.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: loop through values in listbox and search for them in excel sheet

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  5. #5
    Registered User
    Join Date
    06-29-2010
    Location
    Tirana,Albania
    MS-Off Ver
    Excel 2007
    Posts
    1

    Convert text into number format.

    Can someone please help with how to convert text formated cells with numbers into number format cells so can be used into formulas.

    thanx

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: loop through values in listbox and search for them in excel sheet

    Dritrantirane,
    Welcome to the forum.
    Please take a moment to read our rules.

    This thread is about userform list boxes. Your question about text formatted cells would be answered quickest if you were to start your own thread.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: loop through values in listbox and search for them in excel sheet

    longhorn,

    Given that way of filling the list box, I don't see a need to search for the terms.
    Please Login or Register  to view this content.
    should do what you want.

  8. #8
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: loop through values in listbox and search for them in excel sheet

    Well...I when it finds those values in Sheet1, I have to copy those columns in which the values are and then I have to create a new sheet, and paste in those columns...

    (The reason I made a userform is so other's can do this by clicking a few buttons....basically automating the process...)

    I've attached an .xls file if you want to take a look at the code...
    Attached Files Attached Files
    Last edited by longhorn23; 06-29-2010 at 02:19 PM.

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: loop through values in listbox and search for them in excel sheet

    From the OP it sounds to me like you want all of the columns/listbox items.

    Is that the case, or are you looking to choose one item from the list box and get one column of cells.
    If that is the case
    Please Login or Register  to view this content.
    should do it.

  10. #10
    Registered User
    Join Date
    06-21-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: loop through values in listbox and search for them in excel sheet

    Thanks a lot for the help!! I really appreciate it.

    Basically when the columns load into the left listbox, the user will be able to choose and move those chosen values to the right hand listbox. So I'm looking to get ALL of the values in the right hand listbox, whether they be 1 or 3 or 7, etc.....and then create a new sheet, and paste in those columns(<< that part of the code I have, by the way)...

    Also where should I put that piece of code you gave me?
    Last edited by longhorn23; 06-29-2010 at 08:41 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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