+ Reply to Thread
Results 1 to 14 of 14

Add, Edit, Delete items in dynamic listbox

  1. #1
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Add, Edit, Delete items in dynamic listbox

    Hello.
    I've written in the subject of thread "dynamic listbox".
    I don't know if it is correct but you'll understand what I mean opening the test file from the attachment.

    I have two questions:
    - could it be written a code able to create dynamic ranges for the columns from sheet "Liste"? (number of rows in column is variable) I have a code that create the ranges but only with the same lenght with TipDoc range (please see the module CreateDinamicRange).
    - in the "2" section of the userform there are three options: Add, Edit and Delete. Each of this command buttons must Add, Edit or Delete the selected item in the list lstCodDoc. Can it be done?

    I have a code for the Add New Entry command button but it doesn't work in this case because I don't know how the range could be changed.

    Please Login or Register  to view this content.
    Thank you.
    Attached Files Attached Files
    Last edited by zvonacfirst; 02-15-2017 at 04:12 AM. Reason: Correction

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    So you want to be able to modify the selected listbox by either removing or addin items.
    Does Edit work?
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    Two things to change:

    Modify the code in the userform for this macro

    Please Login or Register  to view this content.
    And add place this function in any of the VBA modules;

    Please Login or Register  to view this content.
    To Edit and to delete I did not do anything but with this you can probably build it in
    Last edited by Keebellah; 02-15-2017 at 06:25 AM. Reason: Info

  4. #4
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Re: Add, Edit, Delete items in dynamic listbox

    Thank you.

    The code for cmdAddDoc works fine, but a line is not in good place.
    It's about "Call CreateColumns". This line is not necessary here. The macro "CreateColumns" runs with cmdAddNewType. After the new item adding, this command create the new column with the same name with the new item.

    What is the role of the second code?

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    Create Columns is necessary to 'refresh the data and make sure it's registered.
    The second code is to identify the column that you are modifying.

  6. #6
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Re: Add, Edit, Delete items in dynamic listbox

    OK.

    I added a line in next code:

    Please Login or Register  to view this content.

    Does Edit work?
    No, Edit doesn't work. Also Delete.
    What do you think about?
    Last edited by zvonacfirst; 02-15-2017 at 10:15 AM. Reason: Correction

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    I did not do anything with Edit and Delete.
    I just gave you the code Add.
    The part to Edit and Delete will have to be approached in another way.
    Do you want me to write that for you too?

    What does the code do that you added?

  8. #8
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Re: Add, Edit, Delete items in dynamic listbox

    Quote Originally Posted by Keebellah View Post
    The part to Edit and Delete will have to be approached in another way.
    Do you want me to write that for you too?
    Yes, please! Thank you.

    Quote Originally Posted by Keebellah View Post
    What does the code do that you added?
    - Edit code should be able to modify an item selected in listbox 2. The selected item should appear in the text box upper the Edit button. It should be edited (I mean change the name) and confirmed by the Edit button.

    - Delete code should delete an item selected in listbix 2 (with no blank cells). The text box upper the Delete button can be deleted, it is useless.

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    Yes I understand that, that is why the way you have set it up needs some minor modifications, I will place English text in the message boxes which you will have to translate to Romanian.

    I hope you will not mind that I will change you code a little.

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    Okay, I did not make too many modifications.
    I changed the userform where you had EDIT and DELETE
    I also added conditional formatting to the "Liste" so if the cell is not empty you get a border
    It all seems to work now as far as Add, Edit and Delete

    If you have any questions, just post
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Re: Add, Edit, Delete items in dynamic listbox

    Thank you very much for your help.
    Your solution it is wonderful.

    A single and last question:
    - for the Add New Entry button could be inserted a line for checking for duplicates? If the new entry already exist in the range, should apear a msgbox: This item already exist.

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    You have the sample, try it, do you think you can, that is the best way to learn VBA.

    Just add a routine to find the value in that column, if found the exit.

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Add, Edit, Delete items in dynamic listbox

    Okay, here is the code, I think I took care of all possibilities too, also when you edit it will check if the new value exists.
    I added one function so you can use if you more than one situation, you just pass the column letter and the text to check
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Re: Add, Edit, Delete items in dynamic listbox

    THANK YOU!
    Your help was very valuable.

+ 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 ListBox Items
    By Boechat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2016, 10:53 AM
  2. is it possible to edit items of a listbox in excel VBA
    By maggie_xio in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-03-2015, 05:46 AM
  3. Select & edit items in a listbox in VBA
    By poppy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-04-2014, 04:47 PM
  4. [SOLVED] Add Last Six Items to Listbox From dynamic range
    By s2jrchoi in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-26-2013, 02:35 PM
  5. VBA edit listbox items on userform
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 03:51 AM
  6. Edit listbox selected items and save to workbook???
    By madforit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-23-2012, 08:00 AM
  7. [SOLVED] Edit Add Delete Listbox Records
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-10-2005, 06:58 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