+ Reply to Thread
Results 1 to 19 of 19

How do I code an Edit button for a userform?

  1. #1
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    How do I code an Edit button for a userform?

    Howdy,
    In the attached workbook there is a userform that once it is filled out and the submit button is clicked, the information is transferred into the excel spreadsheet. This works perfect for what I need it to do. There are a couple of other buttons that have been deactivated for the purpose of this sample workbook so no issues there.

    Here is my dilemma:
    Thanks to "layer 8" issues, I had to add an Edit button to the userform. When it is clicked, the user is to enter the row they want to edit.
    1st) Is it possible to edit based on the row that the user enters?
    2nd) If so, I have no idea how to write the code for this. What I would like to happen is after they enter the row# and click OK, the userform opens with the information from that row populated in the proper TextBoxes and ComboBoxes and then they edit what they need to.
    Now I realize that I may need another button for them to be able to update that row. Sheesh!

    Anywho, is this possible? If not what is an alternative method. If it is possible, is it the best method to use?
    EOSR Sample for EF.xlsm

    PS I have researched this and found a few posts here and on the web, but only one was remotely close to what I wanted (I thought) but when I read into it more, it wasn't.
    Last edited by gmr4evr1; 11-15-2015 at 08:11 PM.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

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

    Re: How do I code an Edit button for a userform?

    I am looking at this for you.

    This is a flag so I can find your post again as I get logged out almost immediately.


    You need to think again about using the row number, that will not be viable if you have 20000 rows

    Think about username and device number.


    Ok this is very easy as you have done 99% of the work already.

    you have the routine

    Please Login or Register  to view this content.
    Which is writing your data to newrow.

    So make newrow a global variable for the userform by declaring it as a public variable at the top of your userform code.
    Define an Edit Flag as a global variable using

    Please Login or Register  to view this content.
    Set this to false when you initialise the userform.

    Now all you need to happen when you Click on Edit is for the Data to be loaded from your data and newrow to be stored
    [ I will show you how to do that in a bit ]
    Then EditFlag need to be set to True

    Then the edit button needs to call your existing save routine:-
    Please Login or Register  to view this content.
    We need a small change in that bit of code too.

    Please Login or Register  to view this content.

    Becomes

    Please Login or Register  to view this content.
    Now all you need your edit button to do is to set newrow to the edit row when you choose the row to edit.

    So I will code the Edit Button For You
    Last edited by mehmetcik; 11-15-2015 at 08:34 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 Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    Thank you very much mehmetcik!

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    mehmetcik,
    I did consider username, device number, lot number, part number and even date. The problem is that one user can have multiple entries for the same device number, P/N, L/N on the same date. Then the user from the next shift could have the same information multiple times on the same date as well. The only thing that might not be a constant is column H, the details column, but that's not a guarantee. This is the reason I was thinking of going with the row number.

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

    Re: How do I code an Edit button for a userform?

    Can You not Create a Reference Number of Some Description

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

    Re: How do I code an Edit button for a userform?

    Can You not Create a Reference Number of Some Description

    Also you should be using data validation.

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    I'm pretty new to this so I have no idea how to answer that question as I don't understand what you mean.
    Also, I'm not familiar with data validation.

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

    Re: How do I code an Edit button for a userform?

    Ok this will take a while.

    You have a hidden sheet with your masterlist that you are using for some of your data entry

    you should be using that for all your data

    I have created some dynamic named ranges on the attached document.

    Run the macro test to see how they work.

    They are similar to rowlist

    Just something to look at for now as it is late here
    Attached Files Attached Files

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How do I code an Edit button for a userform?

    Couldn't you have the user double click the row they want to edit?

    Then you could use the sheet's BeforeDoubleClick event to load the form and populate it with the relevant data.

    You'll probably want to store the row number to use when you send the data back to the sheet from the userform.
    If posting code please use code tags, see here.

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

    Re: How do I code an Edit button for a userform?

    Norie's suggestion worked out.
    Double click any value in table to edit.
    Double click empty row to add new entry.
    Attached Files Attached Files

  11. #11
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    Norie,
    Great suggestion! I didn't even know that was an option.
    bakerman2,
    Sweet!I believe the update you provided will work out for me.
    mehmetcik,
    I tried yours, had to change a few things, and will look at it some more to figure things out with it. I would still like to see what you come up with.
    Thanks to ALL of you for helping me with this!!!!
    Last edited by gmr4evr1; 11-16-2015 at 04:55 PM.

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

    Re: How do I code an Edit button for a userform?

    You're welcome and thanks for the rep.

  13. #13
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    No problem, it was well deserved.

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

    Re: How do I code an Edit button for a userform?

    Ok Sorry about the delay.

    I rebuilt your userform because there were a few tricks that you missed out on.

    Try this version for size, it should be quite intuitive,

    however in edit mode you need to type or select your entry in a combobox and then click on another combobox to start the search routine.

    Enjoy.
    Attached Files Attached Files

  15. #15
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    mehmetcik,
    No worries about the delay. You have really rebuilt what I originally had. I haven't had a chance to go through it all yet, but there is one thing I really like about it so far. I love the fact that the user can add info such as a defect reason if it doesn't already exist. That was going to be one of the next things on my list to research and/or post in here. Now I don't have to thanks to you!
    As soon as I get "down time" at work, I will look into it more.
    Thank you very much for providing me with your version.

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

    Re: How do I code an Edit button for a userform?

    I'm afraid I screwed up.

    I worked out how to sort the Data as you add new data, then forgot to include it into my Rebuild. Duh.

    So i am posting it for you before I lose it.

    I also put some conditional formatting in the Data Sheet to color alternate rows.

    The final bit of code makes column C's format General, this is because your press numbers confuse excel.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  17. #17
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    Thank you mehmetcik. I still like the idea that a user can add new data because for 1 or 2 of the columns that will be helpful to me. However, I/we can't have them doing it for all the columns because some of them are "static"(?) lists, like the equipment# (press number) list, this cannot be changed by anyone but me. It has to be in a specific format and specific order and we have already discovered that the users can, will and have used up to 4 different formats for the equipment #. Going back to my original sample file, the employee name column is actually populated with the "currentuser()" code and the user never even sees this textbox on the form as it automatically filled out for them, so this one cant be changed by the user.
    Basically I would like them to be able to add new data to the defect column and MAYBE the part number columns only.
    The reason I originally had the sheet in a table format was because management wants to be able to open the workbook and filter by press#, defect, employee (another reason employee can't be changed by user), and/or date, etc. etc.

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

    Re: How do I code an Edit button for a userform?

    I thought you might want some controls but I left that for you to do.
    You created the original name check so I thought you might be able to adapt that.

    All you need to do is modify the new entry routine.

    this line

    Please Login or Register  to view this content.
    just above the 'New Entry comment would do the trick.

    simply check username and if it is you then allow any value of choice

    If anyone else then accept only the specified columns.

    You can filter simply by selecting the required field in the combo boxes giving you 5 filters
    Last edited by mehmetcik; 11-19-2015 at 09:39 PM.

  19. #19
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How do I code an Edit button for a userform?

    Okie dokie, thanks mehmetcik. I will check it out as soon as I get "free" time.

+ 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. Can't get userform code to edit/append/delete comments
    By misty15 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2015, 05:32 PM
  2. Userform Save and Edit Commnad Button
    By McGuire1986 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2015, 01:07 PM
  3. [SOLVED] SUM when click button - level 2 (code edit)
    By Viktor86HUN in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-24-2014, 03:59 AM
  4. Help with coding an edit row button form a userform
    By Stephen_Malley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-10-2014, 07:53 AM
  5. [SOLVED] Userform code fails when the userform is called from a custom ribbon button
    By klonbeck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 03:00 PM
  6. Edit VBA Userform code to run if only 1 entry that matches criteria
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-24-2013, 05:25 AM
  7. VBA Code to Search/Edit Data Populated by Userform
    By pjohnson9 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2011, 04:25 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