+ Reply to Thread
Results 1 to 8 of 8

Listbox Data in UserForm Not Passing to Spreadsheet

  1. #1
    Registered User
    Join Date
    04-10-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    2

    Listbox Data in UserForm Not Passing to Spreadsheet

    It's been a long time since I've used VBA, so pardon the memory loss.

    I created a UserForm to add/edit data on a spreadsheet. All pretty straightforward stuff. I have a bunch of text-boxes, a couple of combo-boxes, and a few list-boxes. Everything in the form looks great - all the controls appear to be set up correctly. BUT when I run the form and submit the data to the spreadsheet, the data selected in the list-boxes does not pass to the spreadsheet. The data in the text-boxes and combo-boxes passes just fine - it's only the info in the list-boxes that just seems to go nowhere.

    I'm missing something, like a snippet of code that tells me what the value of the list-box actually is (versus what is simply displayed on the form). I just don't know what the missing code is.

    Any help would be greatly appreciated.

    JD

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Listbox Data in UserForm Not Passing to Spreadsheet

    Where on which worksheet do you want to write the data selected from the listboxes? Are the listboxes single-select or multi-select?

    It would be extremely helpful to see your file, or at least the code you have that already works.

    The paper clip icon does not work for attachments. To attach a file, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    04-10-2014
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Listbox Data in UserForm Not Passing to Spreadsheet

    The code to push the data is just:
    Sheets("Proposals").Range("Data_Start").Offset(TargetRow, 14).Value = list_PRC

    It matches the code to push data for a text box (that does pass the data correctly):
    Sheets("Proposals").Range("Data_Start").Offset(TargetRow, 0).Value = txt_ProposalID

    I think the issue is the value I'm passing - it should be a string since it's a multi-selection list-box, yes? I'm trying this code to determine the proper string value for the field:
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer


    And then the code to pass the data should be this?
    Sheets("Proposals").Range("Data_Start").Offset(TargetRow, 14).Value = list_PRCStr
    Last edited by 6StringJazzer; 10-10-2019 at 11:15 AM.

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Listbox Data in UserForm Not Passing to Spreadsheet

    Without a desensitised upload of your actual workbook it is unlikely that a solution will happen in the near future.
    Your code does not make sense and is unlikely to work no matter what combinations of guesswork are employed.
    torachan.

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

    Re: Listbox Data in UserForm Not Passing to Spreadsheet

    You could put something like this in the Listboxes change event.
    Please Login or Register  to view this content.
    And later, when writing to the sheet, code like this
    Please Login or Register  to view this content.

    I do notice that your existing code is using the .Item property of a Listbox. I believe that the .List property is the one you are looking for.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Listbox Data in UserForm Not Passing to Spreadsheet

    Quote Originally Posted by jd_now View Post
    The code to push the data is just:
    Sheets("Proposals").Range("Data_Start").Offset(TargetRow, 14).Value = list_PRC
    This code uses the list itself, rather than the string you built, which is why it doesn't work. Your code below is the right idea but you will need to declare list_PRCStr in a place where is it visible to both list_PRC_Change (yes, you do want Change instead of Click) and the line of code above.
    Please Login or Register  to view this content.
    And then the code to pass the data should be this?
    Please Login or Register  to view this content.
    Yes. Where is this code?

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Listbox Data in UserForm Not Passing to Spreadsheet

    Quote Originally Posted by torachan View Post
    Without a desensitised upload of your actual workbook it is unlikely that a solution will happen in the near future.
    Your code does not make sense and is unlikely to work no matter what combinations of guesswork are employed.
    torachan.
    This is a bit pessimistic. The code has a couple of errors but makes perfect sense in light of what the OP has explained that he wants to do.

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Listbox Data in UserForm Not Passing to Spreadsheet

    This is a bit pessimistic. The code has a couple of errors but makes perfect sense in light of what the OP has explained that he wants to do.
    Not a bit pessimistic, very pessimistic.
    Over the years recall the number of threads that have run to a dozen or more posts only to find on viewing the 'ACTUAL' code a ; instead of ,
    The 'workbook' is more use than a random piece of 'copy/paste' code.
    Just a 'pensioners' point of view.
    torachan

+ 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] Need Help with textbox when passing data to sheet(UserForm)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-10-2017, 07:43 AM
  2. Replies: 1
    Last Post: 05-30-2015, 12:15 PM
  3. column headings in userform listbox from excel spreadsheet
    By jawirth44 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-07-2015, 06:51 PM
  4. Transfer listbox and textbox data from userform to spreadsheet
    By NellieNoggs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-05-2014, 02:35 PM
  5. Transfer Data From One Userform Listbox to Another Userform Listbox with 11 columns
    By sparkoft in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-18-2013, 10:54 AM
  6. 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
  7. Passing Userform Listbox to sub causes type-mismatch error
    By Kleev in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2005, 04:05 PM

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