+ Reply to Thread
Results 1 to 4 of 4

Get row number from table based on listbox selection

  1. #1
    Registered User
    Join Date
    12-03-2014
    Location
    swe
    MS-Off Ver
    office 2010
    Posts
    57

    Get row number from table based on listbox selection

    How do i get the table row number based on the selection in a listbox?


    I have a listbox that i populate with data from a table.

    I want to select a row in the listbox and get that datas row number from the table.
    Not the row number of the listbox, but the row from the table where the data is stored.

    This problem is really annoying...
    Cant figure out how to approach this.

    If user select data xxx in listbox, search table1 and return row number of result.
    How?
    Last edited by behedwin; 06-10-2017 at 02:32 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Get row number from table based on listbox selection

    If you populate the listbox from a range (say "A2:A10" for this example) then you know the first Item in the listbox is in row two. You could then use the index number of the selected item in the listbox to determine the row number.

    The listbox index numbers start at zero for the first item and increase by one for each item. This will return the row number of the selected item assuming the listbox is filled from a range starting at row 2.

    Please Login or Register  to view this content.
    .ListIndex is the index number of the selected item in the listbox.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    12-03-2014
    Location
    swe
    MS-Off Ver
    office 2010
    Posts
    57

    Re: Get row number from table based on listbox selection

    Quote Originally Posted by AlphaFrog View Post
    If you populate the listbox from a range (say "A2:A10" for this example) then you know the first Item in the listbox is in row two. You could then use the index number of the selected item in the listbox to determine the row number.

    The listbox index numbers start at zero for the first item and increase by one for each item. This will return the row number of the selected item assuming the listbox is filled from a range starting at row 2.

    Please Login or Register  to view this content.
    .ListIndex is the index number of the selected item in the listbox.
    I dont tested this, but it wont work.
    Thing is that my listbox contain data from a larger table.
    I filter out certain things to view in the listbox.
    So if i select data1 on row 1 in the listbox. Data1 can be located on row 50 in the table.

    I want to know what row the data is in the table. So if i click on data1 on row1 in the listbox, i want to get the row number of where data1 is located in the table.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Get row number from table based on listbox selection

    Then the way I would do it is when you populate the ListBox with the filtered items, populate another column in the listbox with the row number of each item. Then when you select an item, you can read its row number as well. The column in the listbox that contains the row numbers could be hidden if you don't want to see it. If you need help on how to do this, attach an example workbook and I'll see what i can do.


    Alternatively, you can use the .Find method to search for the selected Item e.g.

    Please Login or Register  to view this content.

+ 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. Userform to Update Table Values based on a Listbox Selection
    By scottkelley80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-27-2016, 08:49 PM
  2. Replies: 2
    Last Post: 07-15-2014, 08:24 PM
  3. [SOLVED] Listbox selection in form to table
    By eddijensen in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-10-2014, 04:35 AM
  4. Creating a Range of a Listbox based on the Selection Made in Another ListBox
    By masood78 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-02-2014, 11:03 AM
  5. Replies: 12
    Last Post: 08-28-2012, 07:09 AM
  6. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM
  7. populate listbox based on selection in previous listbox
    By sarahng86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2007, 10:55 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