+ Reply to Thread
Results 1 to 8 of 8

How to have a button on a table get added with each new table row

  1. #1
    Registered User
    Join Date
    08-30-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    11

    How to have a button on a table get added with each new table row

    Hi- this is my first post, so please forgive any mis-steps. I have managed to scrub this forum to find enough examples to build a new form from scratch that does a whole bunch of stuff (I'm new to all of this), so thanks to everyone who I have lifted code from so far!

    Here is one I just can't seem to find an answer for:
    I am creating a form with a table, I do not want my users to have to use any excel navigation (assuming little to know excel knowledge for users) to add or remove rows from the table.
    I have created a button at the bottom of the table which will add a new row to the end of the table. This is all working fine.
    I would like for my user to be able to remove a row they had previously entered by clicking on a button residing on the particular row that they want to remove. Basically the same action they would get by going to the row header and deleting.
    So my first question is if I can have each new row that is added to the table contain the delete button (as shown in my attached example where I have attached some "dummy" buttons for illustrative purposes)?
    Second question, assuming the first is possible, how can I attach a macro that will delete that specific row (the one being clicked on)?

    Hopefully this explanation along with the attached file (simplified version of my table) will help clarify what I am trying to do.
    Thanks in advance for any help!
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to have a button on a table get added with each new table row

    Hi ptmakl

    I've modified your Sub AddRow(section As Integer) Code in Module 5 to add a Button to each newly added Row.
    Please Login or Register  to view this content.
    I've added this Code in Module 5 to Delete a selected Row...this Code is assigned to all Delete Row Buttons as they are added.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    08-30-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How to have a button on a table get added with each new table row

    John- Thank you so much for your reply. I may not get a chance to try it for a day or two. But will provide feedback as soon as I can. thanks!

  4. #4
    Registered User
    Join Date
    08-30-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How to have a button on a table get added with each new table row

    This worked beautifully, thanks!

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to have a button on a table get added with each new table row

    You're welcome...glad I could help. Thanks for the Rep.

  6. #6
    Registered User
    Join Date
    08-30-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How to have a button on a table get added with each new table row

    oops, little follow up, any way to make this work with a protected sheet (I'm protecting so the users can't mess with the formulas). I get an error when I try to use the delete button and I'm prompted for a password for the first row I try to add.
    more follow up: have figured out how to unprotect the button when it is clicked, now trying to figure out how to unprotect other protected cells in the affected row so it won't throw the error message.
    Last edited by ptmald; 10-07-2013 at 07:54 PM.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to have a button on a table get added with each new table row

    Hi ptmakl

    In the attached I've added this Code to the WorkBook Open Event...change the Password in the Code
    Please Login or Register  to view this content.
    I've also added this line of Code to your Sub AddRow(section As Integer) Code in Module 5
    Please Login or Register  to view this content.
    to Unlock the User Data Entry Fields.

    Let me know of issues.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-30-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How to have a button on a table get added with each new table row

    Oddly enough, it does everything I need it to do now just with adding the "WorkBook Open Event" code. When I add the "Sub AddRow(section As Integer) Code in Module 5" I start getting runtime errors. The table that I am using this code on is a lot more complicated then the test one I uploaded. It has a lot of conditional formatting, drop down lists and formulas.

    I was trying to get your code to work last night, couldn't get it to work, so decided to reset to where I started before quitting for the night, stripped out the "Sub AddRow(section As Integer) Code in Module 5", but forgot to strip out the "WorkBook Open Event" code.

    Lo and behold, when I opened the file this morning it was working exactly the way I wanted it to with the code I forgot to remove!

+ 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. Insert rows in linked table that are added to secondary table
    By Ida LaValley in forum Excel General
    Replies: 4
    Last Post: 11-16-2020, 12:00 PM
  2. [SOLVED] Pivot Table - Added data
    By lyn402 in forum Excel General
    Replies: 1
    Last Post: 05-13-2012, 11:45 AM
  3. New Column Added To SQL Table Not Showing Up In Excel?
    By ostinoh in forum Access Tables & Databases
    Replies: 1
    Last Post: 02-20-2012, 11:22 AM
  4. Create a new table from the main table when user press Enter button
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2010, 05:08 AM
  5. [SOLVED] Added new columns - Pivot Table not refreshing - why?
    By Joan Sims in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-11-2006, 08:35 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