+ Reply to Thread
Results 1 to 9 of 9

#REF! error appears after deleting a row

  1. #1
    Registered User
    Join Date
    05-08-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    6

    #REF! error appears after deleting a row

    Hi,
    I am getting a sinking feeling that my problem is just how Excel works!?

    Attached is a sample of a worksheet in an app that I developed to track and report van ridership usage. After a lot of hours of time effort the form/app works just great!! Except for one detail: if, for whatever reason, a user may discover that one entry needs to be deleted. When he/she uses either the built-in "form" or right clicks and deletes using the rows index column a #REF! appears in certain cells in the row immediately following the deleted row. No subsequent rows develop this error.

    The attached workbook has 3 worksheets.
    Sheet1 shows the table with 6 rows of data.
    Sheet2 is just for a quick way to view the underlying functions and values.
    Sheet3 shows the two "#REF!" errors at cells H4 and K4. These appeared after deleting the row with ID: 1002. I kind of understand why it happened i.e. the reference to Cell G3 was momentarily lost!? But note that the row with ID 1004 does not have these errors. In other words their references updated correctly.

    What should I do?
    Should I create a custom lookup form with deleting capabilities to handle this problem? Or should I rethink my approach and key in on something else? Or??
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: #REF! error appears after deleting a row

    The #REF! error shows when a formula refers to a cell that’s not valid . This happens most often when cells that were referenced by formulas get deleted, or pasted over

    what to do?
    go to a cell which has the correct it manually
    or
    find a cell of which you can fill the formula from
    in your case H2:K2 fill down
    the problem is if you delete the first row of the table (below the header)
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: #REF! error appears after deleting a row

    Hi mhorniak and welcome to the forum,

    See if the attached works for you. I changed the formulas on Sheet two so they refer to the same row instead of the row below.

    Make Formulas on and about a single row.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    05-08-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: #REF! error appears after deleting a row

    Quote Originally Posted by MarvinP View Post
    Hi mhorniak and welcome to the forum,

    See if the attached works for you. I changed the formulas on Sheet two so they refer to the same row instead of the row below.

    Attachment 573625
    Thanks for the replay MarvinP! Your change removed the if conditions which are needed to make it a dynamic check for each entry.

  5. #5
    Registered User
    Join Date
    05-08-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: #REF! error appears after deleting a row

    Thanks himdingaling I like your funny handle.

    I am aware of the manual approach. But for my users that is not an option. I was hoping someone could really explain why the #REF! error was occurring because the next row (ID 1004) correctly updated. When ID 1003 moved from A5 to A4 after the deletion of ID 1002 the formula should have updated from "=IF(G5=G4,0,G5-F5)" to =IF(G4=G3,0,G4-F4) instead it became =IF(G4=#REF!,0,G4-F4). The three other cells in that formula did correctly update!

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: #REF! error appears after deleting a row

    The best way around this is to NOT delete rows. If necessary, delete the contents of the cells.

    The ref error is because the formula is referencing a cell whose entire row have been deleted. The cells below and above, have not had "their" rows deleted, so they show no error.

    To see this happen, open a new file or sheet, in A1:Aa3 enter something (doesnt matter what), then in A5, enter =A1 and copy it down twice. Now delete row 2, you will see that (the new) A4 still calcs properly, A5 shows REF and A6 calcs OK. the REF is because you deleted the row that (the new) A5 referenced
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Registered User
    Join Date
    05-08-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: #REF! error appears after deleting a row

    Hi FDibbins
    Thanks for your input and example. Well it is what it is then! There is no magic fix. I'm going to have to come up with a creative solution. Or perhaps use some version of your idea not to delete the row but just the contents. There is a report that gets automatically generated at the end of the app. I'll have to see if your idea will affect its output.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: #REF! error appears after deleting a row

    You might alter H2 thus
    =IF(G2=INDEX(G:G,ROW()-1),0,G2-F2)
    and K2 thus
    =IF(G2=INDEX(G:G,ROW()-1),0,MOD(J2-I2,1)*24)
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  9. #9
    Registered User
    Join Date
    05-08-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    6

    Re: #REF! error appears after deleting a row

    What an elegant solution! I will NOT forget it.
    Thank you very much xlnitwit.

+ 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] Deleting Rows if Value Appears in Another Table
    By thesonofdarwin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2017, 12:41 PM
  2. Userform VBA Password Box Appears before deleting select data
    By kirana2014 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-26-2016, 12:42 PM
  3. Deleting what appears to be a watermark
    By TTERRIE in forum Excel General
    Replies: 6
    Last Post: 05-20-2016, 10:16 AM
  4. Replies: 2
    Last Post: 02-03-2016, 12:23 PM
  5. Error in interpolation when a new day appears
    By elfvis in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-01-2007, 10:05 AM
  6. [SOLVED] line appears when deleting chart- cannot delete it
    By Brian in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-20-2006, 08:50 AM
  7. Appears error (424)
    By 007007007 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-10-2005, 10:00 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