+ Reply to Thread
Results 1 to 2 of 2

Macro to Insert Line & Transfer Formula Not Updating Cell References Correctly

  1. #1
    Forum Contributor Big.Moe's Avatar
    Join Date
    03-15-2012
    Location
    Corea, Maine, USA
    MS-Off Ver
    Excel 2010
    Posts
    244

    Macro to Insert Line & Transfer Formula Not Updating Cell References Correctly

    Hello Everyone,

    A while ago, I created a button in a spreadsheet so that if the user needed to add additional lines, they could just click the button and a VBA code would insert a new row and transfer the formulas to new row.

    Here is the code:
    Please Login or Register  to view this content.
    That has been working perfectly for a couple years, but recently I had to add a column (Col J) in file below that tabulates a running daily total.

    This is the formula in those cells:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Bait Sheet.jpg

    A simple formula that works fine, except when a line is inserted. When you insert a line with the VBA button some of the cell references in the cell immediately below are updated and some are not.

    Here is an example:
    - Original Formula in cell J795: =IF(A795=A794,J794+F795,F795)
    - Line inserted just above pushes cell J795 down and makes it cell J796
    - Formula after line inserted: =IF(A796=A794,J794+F796,F796)

    As you can see, the 795 references were updated to 796, but the 794 references stayed the same, which messes up the calculations. This only occurs in the line immediately following the inserted line. The remainder of the cells below are updated correctly.

    Is there anyway to rectify this?

    Thank you for your time.
    Attached Files Attached Files
    Last edited by Big.Moe; 10-05-2022 at 09:57 AM.

  2. #2
    Forum Contributor Big.Moe's Avatar
    Join Date
    03-15-2012
    Location
    Corea, Maine, USA
    MS-Off Ver
    Excel 2010
    Posts
    244

    Re: Macro to Insert Line & Transfer Formula Not Updating Cell References Correctly

    I did some more research on this issue and found that the problem was not the VBA macro itself, but rather an issue inherent with Excel itself.

    Here is a Microsoft Office forum post that deals with this issue:
    https://answers.microsoft.com/en-us/...7-064c5b6b4c2f

    They offer a clever work around by substituting previous line references with "INDIRECT("A"&ROW()-1)"

    Seems to do the trick.

+ 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. Macro is not Working Properly
    By joao1232 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 05:53 PM
  2. Macro not working properly as add-in
    By TZ Saic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-03-2015, 07:54 AM
  3. macro not working properly
    By cooner3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2014, 10:16 AM
  4. Transfer from WS to WS range not working properly
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-02-2014, 12:39 PM
  5. Macro Not Working Properly
    By fasrose in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 04:49 PM
  6. [SOLVED] Where more than 1 line exists in excel transfer - insert line in word report bookmark
    By PippiLaRue in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2013, 05:04 AM
  7. Macro to insert a line and copy the formula from above
    By dimmockc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-26-2008, 12:59 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