+ Reply to Thread
Results 1 to 25 of 25

Formula referring to wrong cell/row after sorting list?

  1. #1
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Formula referring to wrong cell/row after sorting list?

    I have an issue with a pricelist that I use.

    Basically the list contains several columns with manufacturer, supplier, names, prices etc.
    The prices is calculated by looking at the manufacturer on the same row and matching this against a discount table. So the prices is updated easily.
    This works fine.

    But from time to time there is new products coming in, and I add them on a new row. And then I sort the whole list by manufacturer. And here the problem starts. Suddenly here and there the formula referring to the manufacturer on the same row, is no long referring to the manufacturer on the same row. But instead referring to a cell what seems randomly far away, resulting in calculating the wrong price.

    I am not sure what this problem is called but if someone know what its called and can tell me how to fix this I would be very happy.
    Last edited by vegkol; 02-22-2021 at 06:14 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    I am assuming these formulae to which you refer are simple sheet references, of the type =Sheeet2!A1 - would this be right? If so, then you need to use lookup formulae instead based on each record's unique ID.

    If you want more specific help, upload a sample workbook showing the issue.
    Last edited by AliGW; 02-17-2021 at 04:18 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    The formula I am using is this:
    Please Login or Register  to view this content.
    Where B654 is the cell on the same row I'm referring too. and which is the cell that "suddenly" changes. I can't see how lookup would work here?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    Attach a sample workbook so we can assess the context.

    If you are referring to a static cell whose position might change, you are always going to run into trouble, but there is most likely a way round it. However, I'm not into guessing games, so ... Over to you. Workbook, please!

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Formula referring to wrong cell/row after sorting list?

    This is also quite strange
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    in your formula

  6. #6
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    Ok thanks.

    Will just need to create a duplicate and do some changes to it, as it contains sensitive information.

  7. #7
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    Quote Originally Posted by Pepe Le Mokko View Post
    This is also quite strange
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    in your formula
    This is because its referring to an array. and the # just say it will use all as its dynamic.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    Will wait for the sample workbook - thanks.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    I should have added that switching to structured Excel tables often obviates these issues.

  10. #10
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    Quote Originally Posted by AliGW View Post
    Will wait for the sample workbook - thanks.
    Here is a link to the file
    https://www.dropbox.com/s/4ld7qwkir5...test.xlsx?dl=0

    There is some formating issues in this it seems, but thats not a problem. Look at sheet "ProduktDB" there is the price list in question
    If you look in column "J" you see some #N/A now and this is because they are referring to the wrong cell, this happened when I deleted quite many rows to compress the file/sheet.

    Thank you!

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    Is this a Google Sheets query? If not, please attach the workbook directly here (instructions at the top of the page).

  12. #12
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    No its excel just linket from dropbox
    I uploaded the file now but when clicking the paperclip in here to attach I am not seeing it.
    Attached Files Attached Files
    Last edited by AliGW; 02-17-2021 at 08:42 AM. Reason: PLEASE don't quote unnecessarily!

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    You did it, but the paper clip does not work, which is why I directed you to the instructions at the top of the page. I'll have a look.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    Can you tell us of one specific example for us to focus on - one where you see the problem? Thanks. Which row?

  15. #15
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    On sheet "ProduktDB" the column J has the formula reffering to column B on the same row. It happens on all row. But it seem that when I add new manufactureres and sort the list that the referring cell is no longer on same row.

    By example cell J4 is correct. It now referring to cell B4.
    But when you look at J7 you see a #N/A now and that is because its not referring to B7 but B565 which is wrong. Changing this to B7 the formula is fixed and correct.
    Why this changed from B7 to B565 is mostly because i deleted several hundred rows to compress the file. And when sorting it referred to the wrong cell. But this seems to also happen when adding new products to the list and then sorting the list. The referring cell is then moved resulting in wrong result due to wrong referring cell. not sure if this makes any sense?

    Not sure if $ locking the referring cell would work here, since I often add multiple items at the same time, and then just dragging/copying the cell formula to all other. And if I had $ the cell they would all refer to wrong cell.
    Last edited by AliGW; 02-17-2021 at 08:41 AM. Reason: PLEASE don't quote unnecessarily!

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    There seem to be several issues at play here, not least the fact that some formulae in those columns have been overwritten with manual entries!

    My advice would be to replace your hand-made tables with proper structured tables and see if that makes a difference. You WILL need to update the formula to take advantage of structured references, but once that is done, you should be OK.

  17. #17
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    Not sure I follow, I'm not that good with Excel So an example would be good.
    The formula changes depending on manufacturer, this is due to how we get the pricing. Sometimes we get our prices, but sometimes we get recommended price, so there isn't one formula fits all.

    Thanks
    Last edited by AliGW; 02-17-2021 at 08:37 AM. Reason: PLEASE don't quote unnecessarily!

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    All the more reason for using structured tables.

    Essentially, what you need to do is first switch of autofilters, then select the entire table, then Insert | table ... My table has headers. This converts the range to a table.

    Then you need to change any reference in the top row of formulas to cells within the table by adding a structured table reference (easily done).

    e.g. if you have a reference to F2 in a formula and F2 is part of the table, select F2 in the formula and click on F2, and it will change to a structured reference.

    Once this is done, copy all down and thereafter it should pretty much look after itself.

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    Attached is an example of what I mean. I don't have time to troubleshoot this or check for errors, but it illustrates what I explained in my last post. Over to you now!
    Attached Files Attached Files

  20. #20
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Formula referring to wrong cell/row after sorting list?

    Quote Originally Posted by vegkol View Post
    This is because its referring to an array. and the # just say it will use all as its dynamic.
    I've never heard of that, could you point me to an explanation somewhere?

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?


  22. #22
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Formula referring to wrong cell/row after sorting list?

    Thanks Ali, I don't have O365, Linux doesn't run it yet AFAIK

  23. #23
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    No - it's for info, really. It was new to me, too, but I can see many uses for it.

  24. #24
    Registered User
    Join Date
    06-18-2020
    Location
    Norway
    MS-Off Ver
    365
    Posts
    26

    Re: Formula referring to wrong cell/row after sorting list?

    Thanks all I got it working finally.

    It was mainly solved pretty easily. and reason was that it was referring to the cell the wrong way. it was reffering to it
    Please Login or Register  to view this content.
    And when sorting this didn't follow properly. Replacing this with just
    Please Login or Register  to view this content.
    solved it, and it now sorts without messing it up.

  25. #25
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,453

    Re: Formula referring to wrong cell/row after sorting list?

    Thanks for letting us know.

+ 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] VBA, User-defined formula argument referring to cell value calculated by Excel formula
    By ARAGORN II in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2017, 01:57 PM
  2. Formula referring to cell above
    By ChrisXcel in forum Excel General
    Replies: 3
    Last Post: 04-02-2014, 01:34 AM
  3. Referring to a Cell within a Formula
    By clid82 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 09-29-2013, 02:50 AM
  4. [SOLVED] Formula Referring to Row of Cell
    By monkeycookie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-09-2012, 03:43 AM
  5. Sorting data and referring to the labels
    By saini in forum Excel General
    Replies: 3
    Last Post: 11-02-2009, 01:03 PM
  6. macro referring to a cell that contains a formula
    By tweety127 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2008, 09:07 PM
  7. [SOLVED] formula works when referring to one cell but not to another
    By Nicci in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-07-2006, 09:10 AM

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