+ Reply to Thread
Results 1 to 9 of 9

Populate Textbox from offset cells when selecting listbox item

  1. #1
    Registered User
    Join Date
    07-24-2014
    Location
    London
    MS-Off Ver
    MAC 2011
    Posts
    8

    Populate Textbox from offset cells when selecting listbox item

    Apologies if this is already here, but I have searched and cannot find a solution for my situation!

    I have a userform with a listbox showing 3 columns. I would like to populate a text box with data when I select a row in the listbox. Columns 1 through 3 are shown in the listbox. When I click on an item I want column 4 from the row to be shown in the textbox.

    The listbox is populated using this code: -

    Please Login or Register  to view this content.
    When I click on an item in the listbox this code is executed: -

    Please Login or Register  to view this content.

    The above code also populates an image holder with a photo from the filepath of the worksheet matching the name of the item I click in the listbox. The problem I'm having however is with this line: -

    Please Login or Register  to view this content.
    All I get is a copy of the text shown in the listbox printed in the textbox. It appears to be ignoring the offset. It doesn't matter what I change it to!

    Ideally what I want is: -

    For columns 1 - 3 to show in listbox and when I click on it, column 4 (not shown in listbox) to populate textbox1.

    Col1 Col2 Col3 Col4(not shown in listbox)
    Name DOB Gender Address

    Many Thanks in advance!

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Populate Textbox from offset cells when selecting listbox item

    To get the fourth column value from the listbox, try this....

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    07-24-2014
    Location
    London
    MS-Off Ver
    MAC 2011
    Posts
    8

    Re: Populate Textbox from offset cells when selecting listbox item

    Thanks for your reply, would this work however when the listbox is not being populated with that data? I'm only populating it with 3 columns?

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Populate Textbox from offset cells when selecting listbox item

    If the RowSource has 4 columns in it, it would work even if you allow ColumnCount to 3 only.

  5. #5
    Registered User
    Join Date
    07-24-2014
    Location
    London
    MS-Off Ver
    MAC 2011
    Posts
    8

    Re: Populate Textbox from offset cells when selecting listbox item

    Sorry, but confused (very new to this!), but I'm not using RowSource to populate the listbox. I'm using a defined Name Range in the worksheet which I then define in the code "NameFound". This is a defined range of 1 column in the worksheet. I am still able to populate the listbox with as many columns as I want, but just use the defined range when searching it.

  6. #6
    Registered User
    Join Date
    07-24-2014
    Location
    London
    MS-Off Ver
    MAC 2011
    Posts
    8

    Re: Populate Textbox from offset cells when selecting listbox item

    Even why I try this way, I still just get a copy of what the first column in the listbox says, printed in the textbox: -

    Please Login or Register  to view this content.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Populate Textbox from offset cells when selecting listbox item

    Your listbox is populated with the following line...

    Please Login or Register  to view this content.
    In the UserForm Activate code where you are populating the array MyList, populate the fourth column also with the desired column from the sheet.

    Please Login or Register  to view this content.
    Then Me.TextBox1.Text = Me.ListBox1.Column(3, Me.ListBox1.ListIndex) would work for you.

  8. #8
    Registered User
    Join Date
    07-24-2014
    Location
    London
    MS-Off Ver
    MAC 2011
    Posts
    8

    Re: Populate Textbox from offset cells when selecting listbox item

    Hi,

    Thanks for that, I've tried doing as you said but I am still only seeing the data from column 0 being printed in the textbox...am very puzzled by this! I've tried changing column numbers and offsets etc, but still no joy. Am I missing something?! I would post the entire workbook for you to look at, but as it is an already populated sheet with sensative data I am unable to do so. Any other ideas?

  9. #9
    Registered User
    Join Date
    07-24-2014
    Location
    London
    MS-Off Ver
    MAC 2011
    Posts
    8

    Re: Populate Textbox from offset cells when selecting listbox item

    Ok cancel that! I found the issue. There was some rogue code further down where for some reason under textbox1 change there was code saying TextBox1.Text = ListBox1.Value.....(!) Sorry for wasting your time! But one further question, will using the method above result in large amount of data being put in the memory when I have over 500 rows of data being called?

+ 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] Add TextBox for each item checked in ListBox
    By xforce1983 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-10-2015, 03:33 PM
  2. [SOLVED] Selected Listbox Item to Textbox
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2014, 04:07 PM
  3. [SOLVED] Displaying item from a listbox in a textbox with next 2 columns
    By kmakjop in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-25-2014, 08:44 PM
  4. [SOLVED] Display Selected Item in Listbox in Textbox
    By puuts in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-14-2014, 04:19 PM
  5. Select listbox item then appear textbox
    By sohaila in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2013, 04:41 AM
  6. Populate ListBox Based On Item Chosen In Another ListBox
    By davemojo82 in forum Excel General
    Replies: 1
    Last Post: 08-04-2009, 08:39 AM
  7. [SOLVED] Selecting a listbox item event
    By Todd Huttenstine in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-27-2005, 04:05 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