+ Reply to Thread
Results 1 to 14 of 14

Code to add new row and copy formulas only (not values)

  1. #1
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Code to add new row and copy formulas only (not values)

    Im looking for code to add new rows and copy the formulas only (not values) into the cells A, B, C, D and F. I have found code that does this in various places online but in every case I have found they duplicate the row then remove the values (so the formulas are left behind). The issue I have however is that it triggers some change event code I have on the sheet which interrupts the process.
    Is it not possible to simply insert a new blank row, then copy down the formulas only without values?

  2. #2
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Code to add new row and copy formulas only (not values)

    you have excel2011, so make a table of your data, so if you add new data the formulas are added immediately.
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Code to add new row and copy formulas only (not values)

    formulas utilize values and can refer to other cells (and their values) and render a result unless there is an error triggered . Could you send a sample workbook?

  4. #4
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Code to add new row and copy formulas only (not values)

    Im trying to avoid tables because I have not had much success with them, and i would like to make my workbook still compatible with older excel of versions.
    Is this not possible to do with VB?

  5. #5
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Code to add new row and copy formulas only (not values)

    I have attached my workbook rcm. On the ReturnData sheet, my plan is for the user to make a cell selection within the sheet records and then allow the user to input the number of rows they wish to add (the code currently requires the user to select cell within a record). It would then add the number of blank rows entered below the active cell with the formulas in cells A, B, C, D and F remaining.
    Thanks,
    James
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Code to add new row and copy formulas only (not values)

    perhaps you had bad experience with tables, but the unlimited use of rows in your sheet isn't that good for the speed of your sheet.
    Using the max numbers of rows (>1million) is a bad way. Use Defined names like I did with "MyEquipment". Then you can use that in the F-column of "ReturnData"
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Code to add new row and copy formulas only (not values)

    Thank you bsalv.
    However when adding rows in-between existing records, one row adds fine, but if multiple rows are added then the value of E gets copied into all rows except the first.

  8. #8
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Code to add new row and copy formulas only (not values)

    Other than changing that code for the existing records on ReturnData what else did you do to get the file nearly 200 kb smaller?

  9. #9
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Code to add new row and copy formulas only (not values)

    in your userform change the value 1 into r
    Please Login or Register  to view this content.
    I used the defined name "MyEquipment" in the F-column as mentioned in my reaction.
    Do the same in "Search". There you have a lot of unused rows with formulas that look in a huge range. As you work with macros, fill that sheet by a macro and not by formulas.

  10. #10
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Code to add new row and copy formulas only (not values)

    Thanks, I will look into that.
    That line of code however has the same affect. The values still remain in E column (from the second new row added on)

  11. #11
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Code to add new row and copy formulas only (not values)

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Code to add new row and copy formulas only (not values)

    That fixed the issue of keeping the E cells blank, however it created another issue that it now no longer copies over the formulas to the B, C, D and F cells (Just the A cells only still contain the formula).

  13. #13
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Re: Code to add new row and copy formulas only (not values)

    Any thoughts on how to fix this bsalv?

  14. #14
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Code to add new row and copy formulas only (not values)

    see attachment
    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. vb code does not see values and does not work on formulas
    By snobl01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2014, 11:42 AM
  2. [SOLVED] Macro is missing code to copy formulas as well as values
    By Alana L in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2013, 11:04 AM
  3. Modify Code to copy only value not formulas
    By xned in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-08-2009, 11:21 PM
  4. insert row, copy formulas, have code example (I think).
    By gobbolino in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2007, 12:10 AM
  5. [SOLVED] Copy formulas via Code
    By Cordobes in forum Excel General
    Replies: 1
    Last Post: 12-11-2005, 10:55 AM

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