+ Reply to Thread
Results 1 to 15 of 15

Row delete macro is effecting record count formula and vlookup code. #REF!

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

    Row delete macro is effecting record count formula and vlookup code. #REF!

    I have created some VB code for deleting a row (See attached Equipment Return Log, on ReturnData sheet. Clicking Delete Row will remove the row containing an active cell). However when a row gets deleted it effects my A column formula which list the record number with the following formula:
    =IFERROR(IF($D7="", " ", $A6+1), "")

    When the row is deleted, the A cell formula in the row below changes to:
    =IFERROR(IF($D7="", " ",#REF!+ 1), "")
    and no longer displays the record number for any rows below.

    I tried changing this formula to the following code (attachment Equipment Return Log2):
    =IFERROR(IF($D7="","",INDIRECT(ADDRESS(ROW()-1,COLUMN()))+1),"")

    While this fixes the issue of the record number not working when the records are deleted it prevents some vlookup code from working on the Search sheet. If you go down to row 334, (which contains the last record from the ReturnData sheet) it starts adding blank records. When using the delete record macro the A column on ReturnData sheet now appears to correctly list all the record numbers below, however on the Search sheet a blank row gets left behind where that record used to be, and the vlookup formula on that blank row gets changed to:
    =IFERROR(VLOOKUP(ReturnData!#REF!,ReturnData!$B$6:$K$49972, 3, FALSE),"")

    Im not sure if the issue is with the record number forumla on the A column, the vlookup formula on the Search page, or both. And I dont see how the Column A formula on ReturnData! is effecting the vlookup formula on Search! since the vlookup code only references columns D to K.

    Thank you for your time,
    James
    Attached Files Attached Files

  2. #2
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    Use index or address formula to over come your problem

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    Try this............

    =IFERROR(IF($D6="", "", ROW(A6)-ROWS($A$1:$K$5)),"")

    Hope it helps.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

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

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    Thank you for your responses.

    nflsales, im not to familiar with index and address formulas. Im assuming that would help get around the #REF! issue. How could I change the vlookup formula to get around that?

    sktneer, that record count formula seems to have the same effect as the one I have on Log2. It handles deleted rows fine, but it causes the vlookup on the Search page to created blank records with 0's in every cell (after the last record is displayed).

    Im guessing both of these issues are related to the vlookup formula.
    Any thoughts?
    Thanks,
    James

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    OK. May be you can try this....

    =IFERROR(VLOOKUP(INDIRECT("ReturnData!A6" & ROW()),ReturnData!$B$6:$K$49969, 3, FALSE),"")

    Change all your formulas in the same way on the Search Sheet.

    See if this helps.

    Note: Don't forget to change the formula in A6 as I suggested above (in post #3) on ReturnData sheet.

    =IFERROR(IF($D6="", "", ROW(A6)-ROWS($A$1:$K$5)),"")
    Last edited by sktneer; 10-20-2013 at 01:26 AM.

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

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    sktneer, I tried the new lookup formula (along with your row count formula), but every record in the search page just comes back as 0 for each cell.
    See attached workbook.
    Attached Files Attached Files

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    One more try.....

    On Search sheet in row 11 replace all the formulas with

    C11=IFERROR(VLOOKUP(INDIRECT("ReturnData!A6"),ReturnData!$B$6:$K$49971, 3, FALSE),"")
    Change all the formulas in all the columns of row 11.

    on ReturnData sheet

    A6=IFERROR(IF($D6="", "", ROW(A6)-ROWS($A$1:$K$5)),"")

    on sheet ReturnData sheet copy the above formula down.

    Then try to delete a row 6 from ReturnData sheet and see if you have correct data on Search sheet in row 11.

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

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    For some reason the vlookup formula isnt copying down to the cells below correctly. The A6 isnt counting up, it just remains A6 (so each row comes back with the same data) I tried adding a $ infront of the Letter, but that didn't help. I then tried manually entering it for the first three rows, and then copying that down, but it just kept repeating A6, A7, A8 over and over again. Manually entering the entire page would take forever!

  9. #9
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    Yeah that problem I faced too. But what happened when you deleted a row 6 from ReturnData sheet? Did you get the values then in Search sheet in row 11 or not?

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

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    I deleted row 7 (since I have rows 6-8 with the correct data on the search) and it seemed to react correctly on the search page. But some of the issues I was having with the previous code was that it was adding blank records (with 0's) to the end of the search results. So without filling that code on the search page its hard to say for sure, but its looking promising.

  11. #11
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    Instead you can replace ReturnData!A6 with INDIRECT("ReturnData!A"&ROW()-5) so when you copy it down the row number will change. In the formula shown INDIRECT("ReturnData!A"ROW()-5) will refer to ReturnData!A6.

    Hope it will help.

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

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    Is this what C11 in Search should be? It came back blank:

    =IFERROR(VLOOKUP(INDIRECT(INDIRECT("ReturnData!A"&ROW()-5)),ReturnData!$B$6:$K$49970, 3, FALSE),"")

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

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    Sorry, wasn't thinking straight, the following code returned the correct results:
    =IFERROR(VLOOKUP(INDIRECT("ReturnData!A"&ROW()-5),ReturnData!$B$6:$K$49970, 3, FALSE),"")

    It handles deleted records just fine now (thank you). The only issue as I suspected is it still creates blank records with 0's in each cell. See attached workbook. The Search sheet correctly displays all 317 records, then on line 328 it starts creating blank records.
    Attached Files Attached Files

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

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    I made some development. I went into the preferences and disabled show zeros, which removed all the blank records it was creating. So it now handles deleted records correctly, and does not display blank records (with zeros) anymore. However as soon as I enter a search criteria on the search page, it displays the first record on the Return Data page over and over again from row 328 (with no search criteria entered the last record, record 317 finishes at row 327).

    I have attached the workbook. With no criteria you will see the last record on the search page on row 327. If you hit the TODAY macro at the top (which will return no results since there are no records entered today), the first record will be duplicated from row 328 on. How can I fix this?

    Thanks,
    James
    Attached Files Attached Files

  15. #15
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Row delete macro is effecting record count formula and vlookup code. #REF!

    The issue I was working on were as follows.
    1) When you delete a row from ReturnData sheet, the Entry nos. in column A was turning to blanks. Which is corrected by the changing the formula in ReturnData sheet to
    A6=IFERROR(IF($D6="", "", ROW(A6)-ROWS($A$1:$K$5)),"")

    2) After deleting a row on ReturnData sheet, the Search sheet was returning blank in Row 11. Which is also corrected by changing the formula in C11 to
    C11=IFERROR(VLOOKUP(INDIRECT("ReturnData!A6"),ReturnData!$B$6:$K$49971, 3, FALSE),"")

    So now the original issue has been resolved, I think so.

    I think there are lots of codes attached to your workbook. You need to look at them one by one.

    I can not save your workbook as I am using earlier version of excel and if I save it, all the macros are disabled. And I do not have newer version of excel, therefore its difficult for me to look at all your codes to know if they are working correctly. Your workbook is not allowing any undo if I wish to undo any changes in the formula later. So everytime, I had to close the workbook and reopen it for further working. It took lots of my time as well. Somehow I managed to work on the two basic issues mentioned above. I hope you understand.

    Now once you are getting records on Search sheet, it will not take much time to find out the reason for why you are not getting correct records after a particular row ( As you said "Search sheet correctly displays all 317 records, then on line 328 it starts creating blank records").

    I hope you understand.
    Last edited by sktneer; 10-20-2013 at 11:40 PM.

+ 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. Row delete macro is effecting record count formula and vlookup code.
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 10-13-2013, 06:23 PM
  2. Replies: 1
    Last Post: 01-03-2013, 01:13 AM
  3. [SOLVED] vba code to record a macro
    By green fox in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2006, 05:50 PM
  4. Macro Effecting Formatting
    By whornak in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-19-2005, 06:10 PM
  5. [SOLVED] how to get a macro to record F2, Home, Delete keystrokes
    By jenonstx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2005, 02:05 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