+ Reply to Thread
Results 1 to 9 of 9

Adding & Deleting Rows in Worksheet while maintaining Formulas

  1. #1
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Adding & Deleting Rows in Worksheet while maintaining Formulas

    Good evening. I have a Productivity Report that contains very basic formulas that provide totals for 4 columns (B6:E6) and an average for one column (F). I have included two command buttons, one to add a new row and the other to delete a row.

    I need to be able to add or delete rows depending on how many employees' productivity I will be tracking on any given week; each row represents a separate employee. I need the following functionality out of my form:

    1) formula in column F needs to copy and paste with each new line
    2) when a new line is copied and pasted I need the contents to be cleared
    3) I need the user to be blocked from deleting the first row (3 on this form) in the table

    The code I'm using for my "Add" button is:

    Please Login or Register  to view this content.
    The code I'm using for my "Delete" button is:
    Please Login or Register  to view this content.
    The buttons add and delete rows as I'd like them to but content is not clearing, with each row added the contents provide a sub total. I've tried various lines of code (some more complicated and some less) before I recorded my own macro (see above). Any thoughts or suggestions would be appreciated.

    Matthew
    Attached Files Attached Files

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    How about this macro to delete a row. It will delete the row where the active cell is. This way you can control which row you delete. It also prevents the deletion of row 3.
    Please Login or Register  to view this content.
    Now about your ADD macro, what are those formulas for in your code. I think it is just the last row of your table that should have the SUM function. You or a user will fill in the cells in the table. Right?
    Last edited by p24leclerc; 03-26-2014 at 12:02 PM.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    how about this for your ADD macro:
    Please Login or Register  to view this content.
    You first protect your sheet by allowing all you want the user to be able to do except to delete rows manually.
    Then the macros will unprotect the sheet before adding or deleting a row.

    Here is the delete macro with the unprotect code.
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    Yes, you were correct in your assumption about the formulas. I included your code in to the form and added two lines of code to automatically unprotect a protect the worksheet automatically and BINGO....problem solved. Thanks a lot.

    Matthew
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    Oops...I spoke to soon. I'm getting a run-time error 1004 and the debugger is pointing me to the following line of code. I'm thinking that I deleted one line too many (or something) that now is causing the problem. Thoughts?

    Please Login or Register  to view this content.
    Thanks.

    Matthew

  6. #6
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    Fixed my own problem...silly mistake on my part. I had commented out the unprotect and protect lines of code. It's all good now. Thanks.

    Matthew
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    p24leclerc,

    If you're still game to problem solve, I ran into a few hiccups that I've been trying to work around and I can't seem to lock onto the problem or should I say solution.

    1) I'm trying to prevent the user from deleting the first row (row 3). Once the first row is gone then the form is useless.
    2) I'm trying to get the totals (along the last row) and the averages (in column F) to be blank unless numbers are entered into columns C and E.

    I've been successful in getting a msg box to appear (with instructions for the user) but that's about it. I've got to find a way to make this "dummy proof" which is why I'm putting the effort into such a basic form. Thanks.

    Matthew
    Attached Files Attached Files

  8. #8
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    Look at the attached workbook.
    I modified the "delete" macro so that rows 1, 2, 3 and 4 cannot be deleted as well as the last row "Totals" and formulas. You certainly don't want this row to be deleted either. And you need at least 2 rows of data (3 and 4) for your SUM function to expand as you insert rows in the table.
    I also arranged the formula to show a blank cell if it is in error or a zero.
    Hope this helps.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Adding & Deleting Rows in Worksheet while maintaining Formulas

    That change worked wonders. Thanks a bunch for your help. I've attached the final version of the form here. I included a calendar feature to the form that I received from jaslake (John) on this forum. It worked like a charm. I also added some code that allows text wrap in merged cells and few other tweaks. Thanks again.

    Matthew
    Attached Files Attached Files

+ 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. Inserting and Deleting rows while maintaining formula consistency
    By ChaeDoc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-16-2013, 05:42 AM
  2. Adding Rows and Applying & Maintaining Formulas
    By OZover in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-04-2010, 04:03 PM
  3. Pivot Table - Deleting data rows while maintaining them in the tot
    By Robert Hamilton in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-07-2006, 02:45 PM
  4. [SOLVED] Adding and Deleting rows - update formulas help needed.
    By bperks in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-31-2006, 03:35 PM
  5. Replies: 5
    Last Post: 05-31-2006, 12:50 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