+ Reply to Thread
Results 1 to 16 of 16

Populate Userform with items in a range so user can edit

  1. #1
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Populate Userform with items in a range so user can edit

    I have a userform where users enter in items that will become their drop-down menus. The form works great!

    This is the code for that form:

    Please Login or Register  to view this content.
    However, now I want to add a different form where users can edit this drop-down list. So if they later want to delete or add an item they can. So I need the userform textbox to populate with their current drop-down list (each item on a separate line). Then a user can edit that textbox, and then when they click submit it will be the same previous code so it will create their newly edited list.

    This is my poor attempt:

    Please Login or Register  to view this content.
    But when I click on the form, there is just a blank textbox. I knew this code wouldn't work. It was my poor attempt.

    I just need the form to already have their list in the textbox. And then they can modify that list any way they want, and then on submit, I will have the same code as before.

    Any ideas on how to get the textbox to show the content found in that range, each item showing on a different line.
    Last edited by dsrt16; 03-30-2018 at 11:40 AM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Populate Userform with items in a range so user can edit

    You Should use a listbox for that sort of job.

    Please Login or Register  to view this content.

    You can then programme the click event to remove an entry. You need to do something to prevent the whole listbox being emptied though.


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-29-2018 at 07:30 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    Thanks. I tried that. I am still just getting a blank box when I open the form. I made it a Listbox rather than a textbox and put in your code. I do have the named range correct; it is Clients--I checked and tripe checked. :/

    I named my UserForm EditClient, so the only part of your code I changed was instead of Sub UserForm_Activate() it is Sub EditClient_Activate()

  4. #4
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    ...And apparently that is what I did wrong. I changed it back to just UserForm, and it worked. Is there a reason why it didn't work with the actual name of the user form?

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,363

    Re: Populate Userform with items in a range so user can edit

    I named my UserForm EditClient
    That doesn't matter, leave it as is.
    Please Login or Register  to view this content.
    is to be put in userform module no matter what name the form has.
    It is object related, not name related.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    Ok now I tested out the ability to edit the list. When I clicked in the listbox, I was immediately taken to an error.

    I get object required, and it highlights this line of the code.

    TextBox1.Value = ListBox1.Value

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,363

    Re: Populate Userform with items in a range so user can edit

    Are the names TextBox1 and ListBox1 the names of your objects ?

  8. #8
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    Sorry I was getting dinner ready, and I wasn't paying attention. Oops.

    I got rid of the textbox and just made it a listbox as I thought was what you were suggesting. Or are you referring to the textbox on the original userform where they create the original list?

  9. #9
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    I have two userforms.

    Original one: Enter Clients has a textbox named textbox2, and then the VBA code that on clicking the submit button puts the items in the textbox in the clients named range.

    This new one: Edit Clients, which just has the listbox that auto-populates what is in their clients named range, and then they need to be able to edit it.

    So is the new form supposed to have a textbox too? Sorry, I am not familiar with listboxes. So I just thought you meant replace the textbox with a listbox.
    Last edited by dsrt16; 03-29-2018 at 09:07 PM.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,363

    Re: Populate Userform with items in a range so user can edit

    Why would you need two userforms to add or edit clients ?

    Just add a listbox and a commandbutton to your original.Then use the listbox to select a client you wish to edit. All textboxes get filled with client information.

    Edit the required textboxes and with the new commandbutton write the changes to the worksheet.

    Post an example file with your userform and some dummy info if you have trouble adapting your current userform.

  11. #11
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    I need the original one because nothing is in the client range yet. The first userform is where they first create their user list. Then months or years later, they may want to delete or add one to the list, so then there is the edit userform.

    The first userform populates and creates the client range (which is a named range using offset since I don't know how many clients they will enter in). At the start, there is just a 1 in the first cell of that range to act as a dummy placeholder.

    The user then clicks on create client list and enters in their clients (the 1st userform), and it then puts them into the named range, clearing out the dummy 1, and puts them in alphabetical order.

    I put in Test, Does, This, Work. It then created my client list.

    Then I have a second userform for the user to then edit their client list later on down the road. This is the one you were helping me with.

    So I added a textbox to the edit userform.
    Initial form.png

    When I click on "does," it goes to the textbox.

    1 added.png

    When I click on "test," "this," or "work," nothing happens. I kept clicking to try, and eventually, it would go there, but it would delete "does," and just add a different one.

    I was hoping the user could just edit the textbox.

    So if it comes up with
    "Does"
    "Test"
    "This"
    "Work"
    but the user no longer works with "test," they can just delete it from the list. And if they now work with "crazy," they can add it to the list. So then their new list is "does," "this," "work," "crazy."

    This is my first introduction to a listbox. It seems I can't delete something from the listbox by just highlighting it and deleting it, and I can't add anything to the listbox. So I guess instead of my original idea of a user just deleting an item or adding an item won't work. Instead, I guess they will need to double click on everything in the listbox that they still want to keep to add it to the textbox (thereby deleting the ones they don't want), and then add to the textbox any new entries. Seems extra cumbersome. But as I said right now they can't even select things in the listbox to go into the textbox beyond just one item.
    Last edited by dsrt16; 03-29-2018 at 09:55 PM.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,363

    Re: Populate Userform with items in a range so user can edit

    As I said post an example file with your userform and code you're currently using.
    To do so click on Go Advanced, scroll down to Manage attachments, click Select File, click Upload and then Submit.

  13. #13
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    Ok. I have added my workbook.

    This is what I ideally want.

    On the setup page, they enter in their client list by selecting enter repeat clients. (This is the clients form in the VBE) This form works perfectly. When they click submit, whatever they enter into that box the first time populates on the list page in the clients named range. (The lists page will be hidden, but I have unhidden it for now, so you can see it). If you were to click on enter repeat clients, whatever you put in the box would replace the current dummy list.

    Now what I ideally want is when they click on edit clients, a userform shows up with their current client list, and then they can just simply delete whatever they don't want anymore and add to it what they do want. (This is the EditClients userform in the VBE) Then when they click submit, it then replaces the old client list with the new one. (This can be done with the same code used on the initial form for the submit_click). But what currently isn't working is the ability to edit the list.
    Attached Files Attached Files

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,363

    Re: Populate Userform with items in a range so user can edit

    Select the names you want to delete in ListBox (multiselect) and press Edit list.
    The remaining names appear in Textbox. Now you can add or leave it as is.
    Clicking Submit button writes new list to worksheet.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    11-15-2008
    Location
    Arizona
    MS-Off Ver
    Excel 2013
    Posts
    181

    Re: Populate Userform with items in a range so user can edit

    Thank you so much! You're a genius. This works perfectly!

  16. #16
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,363

    Re: Populate Userform with items in a range so user can edit

    Glad to help and thanks for rep+.

+ 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. edit in code for populate range of cell in list box and code for delete any items
    By mazan2010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2017, 03:33 PM
  2. [SOLVED] Basic User list items , search, Edit from three sheets
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-15-2014, 06:52 AM
  3. Populate row value in userform textboxes, edit and save the changes back in sheet.
    By p_nayak268 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2013, 07:48 PM
  4. [SOLVED] Userform combobox used to populate and edit records does not recognize duplicate names
    By SLJones in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-07-2013, 05:56 PM
  5. [SOLVED] Populate cell values into 6 named text boxes in a userform then edit if required
    By How How in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-05-2013, 05:51 AM
  6. VBA edit listbox items on userform
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 03:51 AM
  7. Populate data in userform and edit
    By surajitbose in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-12-2012, 04:51 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