+ Reply to Thread
Results 1 to 11 of 11

Duplicate second last row of a table

  1. #1
    Forum Contributor
    Join Date
    08-12-2019
    Location
    NYC
    MS-Off Ver
    2019
    Posts
    155

    Duplicate second last row of a table

    Hi,

    I have a table that contains a certain number of lines. Each line contains either input from users or formulas. The last line of my table is just the footer (displaying copyright info). I'm looking for a way to add a line at the bottom of the table (just above the footer) which would still include the formulas (i.e. not a blank line) but none of the user's input of previous lines. The idea is to be able to increase the size of the table by adding a new clean (but not empty, -> formulas still there) line every time the macro is run.

    Attached is an exemple of what I'm looking for.

    Also, I don't know if there is an easy way to duplicate a line with cleaning user data but keeping formulas so I was thinking that an alternative solution would be that the last line of the table (before the footer) is hidden (so the user never uses it to input anything) and is used as template when duplicating / adding new lines.

    Thanks a lot,
    Magnus
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Duplicate second last row of a table

    Well, you're not really using tables...
    Highlight cells A4:E6 and then hit Ctrl-T (to create a table). Tell it that you table has headers. Now, go to cell E6 and hit Tab. This will generate a new row for your table, copying any defined formulae. It should look just like your result.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Forum Contributor
    Join Date
    08-12-2019
    Location
    NYC
    MS-Off Ver
    2019
    Posts
    155

    Re: Duplicate second last row of a table

    Thanks Pauleyb. Sorry I should have mentioned, I'm looking to do that with VBA.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,262

    Re: Duplicate second last row of a table

    One way...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Forum Contributor
    Join Date
    08-12-2019
    Location
    NYC
    MS-Off Ver
    2019
    Posts
    155

    Re: Duplicate second last row of a table

    Thanks Sintek, much appreciated. The formula works great with the example but I'm afraid it would become overly complicated for a table that contains multiple complex formulas in different columns (which is the case in my situation, but not the simplified example). Hence the idea of having the last row of the table being used as a template for duplication by the macro (the last row would be hidden so user doesn't input data and formulas are already all here). By duplicating this hidden line, then I would assume we don't have to even bother with formulas in the VBA code itself.

    Thanks

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,262

    Re: Duplicate second last row of a table

    The formula works great with the example
    Only giving you what you asked for...
    If this is actually not what you require then upload a sample depicting your actual file setup...and explain in detail what you require...
    Anyway, hiding a row for formula template use is not the ideal solution...Have a look at UserForm Interface for data capture...
    Last edited by sintek; 08-02-2020 at 12:41 PM.

  7. #7
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Duplicate second last row of a table

    I am curious why you wish to duplicate in VBA what Excel already does with tables?

    Paul

  8. #8
    Forum Contributor
    Join Date
    08-12-2019
    Location
    NYC
    MS-Off Ver
    2019
    Posts
    155

    Re: Duplicate second last row of a table

    Well, I'm trying to have a button on the spreadsheet that allows a user to easily add a row to a table (while keeping formulas) in a locked sheet. I thought there was no alternative to VBA to do such thing, correct? But maybe I'm missing an excel capability that could easily be associated with a button / macro (not an expert with that).

    sintek: not sure to follow your point regarding UserForm Interface? I'm not trying to capture any data from users, simply add line to a table (or more precisely duplicate the last line in order to keep formatting and formulas in place). The tricky part is that if the last line was already used / filed by the user, I dont want to copy the whole content, hence the idea of have a clean line hidden that could be duplicated and used as a template for additional lines anytime the user runs the macro.

    Thanks a lot for the help
    Best

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,262

    Re: Duplicate second last row of a table

    Still not sure what you are after...See post 6 requirement...
    Last edited by sintek; 08-04-2020 at 01:32 AM.

  10. #10
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Duplicate second last row of a table

    Okay, so the sheet is locked and you want the button to add the row and thus need VBA. I'd still recommend using a Table. Then to add the row, you would do something like this:
    Please Login or Register  to view this content.
    I'll let you determine the proper locked/unlocked state and method.

  11. #11
    Forum Contributor
    Join Date
    08-12-2019
    Location
    NYC
    MS-Off Ver
    2019
    Posts
    155

    Re: Duplicate second last row of a table

    Thank you Pauleyb, it works perfectly. I'm actually surprised that this piece of code is able to add a row while keeping existing formulas intact (I would have thought that it would only add a clean / empty line)

    Thanks 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. [SOLVED] Duplicate a simple table with a Pivot Table
    By virsilens in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 01-30-2019, 06:12 PM
  2. Duplicate a Table and Automatically have it Update as Original Table Updates?
    By tomprestriidge in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 08-16-2018, 12:40 PM
  3. [SOLVED] Copy a row, check table for duplicate, give option to overwrite duplicate before pasting
    By Frankie_The_Flyer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2017, 09:56 PM
  4. Delete Duplicate from Table and Copy them to onother Table
    By ionelz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-28-2016, 07:21 AM
  5. [SOLVED] Duplicate a column of data from a table into new, sorted table
    By JimDandy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-17-2015, 12:53 PM
  6. ID duplicate with table insertion
    By graiggoriz in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-14-2013, 09:35 AM
  7. Duplicate right most value in a table
    By mattieuk in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-13-2007, 01:43 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