+ Reply to Thread
Results 1 to 14 of 14

Delete/add/update list in spreadsheet via User form.

  1. #1
    Registered User
    Join Date
    09-13-2021
    Location
    Guatemala
    MS-Off Ver
    Office 365
    Posts
    5

    Delete/add/update list in spreadsheet via User form.

    I have some problems trying to write the code for this Problem. Especially adding and deleting lineitems (names and phone numbers) in the list and updating the phone numbers.
    Any help is very much appreciated.

    Thank you very much.
    Best regards


    Problem Statement
    Create a user form that allows the user to manage (add, edit, and delete) the names and phone numbers of contacts.

    5 separate subroutines are required:

    • RunForm – the on-sheet button is linked to this sub, which simply opens up the NameForm user form.

    • PopulateComboBox – Prior to opening NameForm, this sub should populate ComboBox1 on NameForm with the names in column A of the spreadsheet.

    • AddName – This sub should enable the user to add another record (row). The name of the new contact is entered into the NewName text box and when the AddButton is clicked, an input box should ask the user for the phone number of the new contact. The new name and phone number should be placed in the next empty row of the spreadsheet with the other data.

    • DeleteItem – After selecting a name from the combo box, the user can delete that contact by clicking on the DeleteButton, which will run the DeleteItem sub. Make sure to remove the deleted item from ComboBox1; otherwise, the deleted item will remain on the drop-down list until the user form is closed.

    • UpdateNumber – The user can select a name from ComboBox1 and modify/update the phone number of that contact by clicking on the PhoneButton. This should run the UpdateNumber sub, which will ask the user for the new number and replace that contact’s old number on the spreadsheet with the new number.

    1616680244942.png
    1616680164514.png


    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Delete/add/update list in spreadsheet via User form.

    This is not exactly what you want,
    but maybe you want to have a look.

    Please Login or Register  to view this content.
    In the userform the controls are :
    1. ComboBox ---> ComboBox1 ---> for name list
    2. TextBox ---> tb1 ---> a textbox to update or add name
    3. TextBox ---> tb2 ---> a textbox to update or add phone number
    4. CommandButton ---> CLEAR ---> is used to add name and phone number
    5. CommandButton ---> DELETE ---> to delete the selected name in the ComboBox1
    6. CommandButton ---> DONE ---> to close the userform

    To update/correction :
    - select the name first in the ComboBox1
    - in tb1 delete the existing text, type the correct name then hit enter on the keyboard (if you want to update the name)
    - in tb2 delete the existing text, type the correct number then hit enter on the keyboard (if you want to update the phone number)

    To add new name and it's phone number
    - click CLEAR button to deselect any name in the ComboBox1
    (this will let the code know that when the user type a name in tb1 then hit enter ---> then this is adding a new data)
    - type the new name in tb1 FIRST then hit enter
    the code will add a new name to the last blank row of column A of the active sheet,
    and call the PopulateComboBox sub to update the ComboBox1 list name.
    - then type it's phone number in tb2 then hit enter
    Please remember the bold text. So, don't fill the new phone number first in tb2.

    To delete the existing data:
    - select the name first in the ComboBox1
    - click DELETE button
    the code will delete the entire row which consist the selected name value in column A
    then call the PopulateComboBox sub to update the ComboBox1 list name.

    First Condition :
    EXCEL_2021-09-18_14-36-32.png

    Update existing data:
    2021-09-18_14-37-21.gif

    Add new name + phone number:
    2021-09-18_14-38-20.gif

    Delete existing data:
    2021-09-18_14-38-48.gif

    Please ignore the post if this isn't what you mean.
    Last edited by karmapala; 09-18-2021 at 02:47 AM.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete/add/update list in spreadsheet via User form.

    There will probably be duplicate names in your Name column so I would urge you to add an extra column with a unique numeric value or ID-number or another combination.

    You can then refer to that unique value in your code to manipulate data to prevent you from updating or deleting the wrong name.
    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.

  4. #4
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: Delete/add/update list in spreadsheet via User form.

    I ripped one of my userforms down to similar to the options u wanted. maybe you can find it useful
    Attached Files Attached Files
    Last edited by unit285; 09-18-2021 at 04:25 AM.

  5. #5
    Registered User
    Join Date
    09-13-2021
    Location
    Guatemala
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Delete/add/update list in spreadsheet via User form.

    Thank you so much for taking the time to do this. I'm having a rough time trying to run mine.
    It says that I haven't define all my variables in the sub PopulateComboBox()

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete/add/update list in spreadsheet via User form.

    You most likely have Option Explicit on top of your module. This forces you to declare all variables you use in your code.

    Take a look at the yellow banner on top of the page on how to attach your workbook.

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

    Re: Delete/add/update list in spreadsheet via User form.

    Take a trip through the code of the attached it has all the basics of 'Add'/'Update'/'Delete'
    To 'Add' first 'Clear' the form for new entry - fill in details then 'Add' - the rest should be intuitive.
    The code is 'longhand' and readable.
    Any queries post back on this site.
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  8. #8
    Registered User
    Join Date
    09-13-2021
    Location
    Guatemala
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Delete/add/update list in spreadsheet via User form.

    Quote Originally Posted by bakerman2 View Post
    You most likely have Option Explicit on top of your module. This forces you to declare all variables you use in your code.

    Take a look at the yellow banner on top of the page on how to attach your workbook.


    This is the excel doc I'm working with
    Attached Files Attached Files

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete/add/update list in spreadsheet via User form.

    Try this for starters.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    09-13-2021
    Location
    Guatemala
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Delete/add/update list in spreadsheet via User form.

    I tried and it works perfectly. I'm just having trouble finding the code in it and since I have to test it on a grader platform, It displays error 9

    Attachment 748271

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete/add/update list in spreadsheet via User form.

    All the code you need is in the userform module. This is how userform code is setup.

    PS: Attachment is invalid.

  12. #12
    Registered User
    Join Date
    09-13-2021
    Location
    Guatemala
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Delete/add/update list in spreadsheet via User form.

    I'll attach again the error. I think it's not finding the form so it does not know what to do next even though I'm running the form myself.

    Edit: I already try deleting "Option Explicit" in my code and it does not work anyways.

    Edit 2: I'll try to attach my grader form too. I'm so sorry to bother you but I will appreciate if you can help me one more time.

    Captura.PNGCaptura.PNG
    Attached Files Attached Files
    Last edited by josefuentes; 09-19-2021 at 01:18 AM.

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

    Re: Delete/add/update list in spreadsheet via User form.

    it would be easier to help if your file was not password protected.

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Delete/add/update list in spreadsheet via User form.

    An error like this arises when something goes wrong on openeing the userform (Userfom_Initialize)

    Since you try to open the form without any data present on the worksheet the Initialize-event goes into Debug.

    To test put some data in the worksheet like your previous example file and try again.

+ 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. Update WS from user form
    By KevBotes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2017, 06:44 PM
  2. Replies: 1
    Last Post: 08-28-2013, 05:04 PM
  3. [SOLVED] Search and Update Records in User Form changing dates to US Format in Spreadsheet
    By JTResearch in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2013, 06:48 AM
  4. I wish to update details in specific rows in an Excel spreadsheet via a user form
    By Ashgaroth in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-08-2013, 06:48 AM
  5. Match new password to specific user and update list via custom user form
    By Sargekd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2011, 09:40 AM
  6. Filling form fields via worksheet dropdowns, user update via form, change form color
    By Demosthenes&Locke in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2010, 08:58 AM
  7. Update List without closing User Form
    By Jogier505 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2010, 04:36 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