+ Reply to Thread
Results 1 to 17 of 17

Can't get listbox which displays rows in sheet to add texbox value to selected row

  1. #1
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Can't get listbox which displays rows in sheet to add texbox value to selected row

    Hi I really need help....with my listbox. I have a listbox that populates with specific rows from a worksheet behind it. The macro searches each row and puts the row in the listbox if it matches certain criteria, namely if column G is not empty and J > 0.

    The listbox populates fine. It's what happens after which I can't get to work. I need the value entered into a textbox on the same userform as the listbox to be entered into a cell on the worksheet corresponding to the row selected in the listbox. This needs to be done after a command button is clicked on. At the moment I click on the button and it does nothing.

    How do I do this?

    Code for populating listbox:
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  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: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    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!
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Sorry Roy, yes of course. Here's a sample workbook with the code I am experiencing problems with above...
    Attached Files Attached Files

  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: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    The ListBox doesn't even load.

    I'll find an example when i get home this evening

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    I suspect it might be easier to store the row numbers in an additional column when you load the list box and then just use that value when writing to the sheet.

    Edit: X-post here.
    Last edited by romperstomper; 07-01-2010 at 10:07 AM.
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Sorry, my mistake. Try loading this.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Hi Romperstomper, yes that could be an option although I want to keep the sheet as 'clean' as possible really. The less surplus data the better. There must be a way I can get Excel to put the selected row into a 'find' routine and search back to the sheet with the end result providing the row i need the data from the textbox to go into.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    I wasn't suggesting you put the row numbers in a column in the sheet, I meant in the listbox!

  9. #9
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Ah I see Hmmmm, hadn't thought of that. Not sure if it would be useful because the problem is that some rows on the sheet are deliberately missed out as they don't match the criteria I mentioned. So if we were to index in that way you couldn't correspond that index back to the row in the sheet, if I understand you correctly!

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

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    This example should help

    FilterForm.zip

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Quote Originally Posted by Julesdude View Post
    So if we were to index in that way you couldn't correspond that index back to the row in the sheet, if I understand you correctly!
    I don't think you do - I mean you store the actual row number of the data you add to the list box. Therefore when you select a row in the list, you automatically have the actual row number of its location in the sheet.

  12. #12
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    I see. I could then hide the column by just declaring the width to be 0 is I didn't want this visible. This could definitely work. But how do I retrieve the row number, put that in the listbox and then reference it after selection to put textbox value into the sheet row?

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    You would need to declare your array as:
    Please Login or Register  to view this content.
    then add dn.Row as the value in the last 'row' of the array as you populate it. When you need to refer to it, you can use the list property:
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Sorry romperstomper, could you post what the code would look like altogether?

  15. #15
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Code in the MainForm:
    Please Login or Register  to view this content.
    Code in the receiptform:
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Thanks for the help so far. It's still not inserting that line for me though when I make a selection and click submit button. Just does nothing.

  17. #17
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Can't get listbox which displays rows in sheet to add texbox value to selected ro

    Worked perfectly for me in your sample file.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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