+ Reply to Thread
Results 1 to 4 of 4

cant sort table differently without changing formula results

  1. #1
    Registered User
    Join Date
    10-05-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    8

    cant sort table differently without changing formula results

    Hi all,

    my problem is to do with cells changing when they are sorted differently e.g. sort Z-A.

    example:=IFERROR((E$11*'PAS TAL 1a'!I6*52/1000),"")

    The first table information is the E$11, which includes hard coded data. When this table is sorted differently this now means the cell E11 includes different data, making the above formula come up with the incorrect amount. How can this be fixed, with a vlookup table perhaps?, how would that work?

    Ideally the formula would change to allow the cell to change to wherever the sort moved the data that was previously in E11, so the formula still involves the correct data.

  2. #2
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: cant sort table differently without changing formula results

    As you've discovered, references point to cells, not to their contents. When you sort a list, it's the contents which change, not the cell references. Luckily, it's possible to get round the problem - here's some methods - which one you choose will depend on your exact circumstances.

    Indirect - fixed
    If the reference is always E11, then replace E11 with INDIRECT("E11"), like this:
    =IFERROR((INDIRECT("E11")*'PAS TAL 1a'!I6*52/1000),"")

    Indirect - changing column
    If you want to be able to drag the formula along/down with the column changing but the row staying the same, it's a bit more complicated. Replace E$11 with: INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(E11),4),1,"")&"$11") which makes your formula this:
    =IFERROR((INDIRECT(SUBSTITUTE(ADDRESS(1,COLUMN(E11),4),1,"")&"$11")*'PAS TAL 1a'!I6*52/1000),"")

    Lookup using Helper column
    Neither of the two options above will work if you want to be able to copy and paste an entire table to another location and keep the formula working. Instead, you can do this:
    1. Insert an additional column to the right of your data - let's assume the new column is column H. It must be next to the data, so that it will be sorted with the data.
    2. In this column, in the row corresponding to the data you want to refer to (E$11, so row 11, so cell H11), type 'Ref' (without inverted commas) or something else which indicates to you that this is the row you want to refer to.
    3. E$11 in your formula can now be replaced with an Index/Match formula which looks up the row containing 'Ref'. This I/M formula is something like this: =INDEX($E$1:$E$15,MATCH("Ref",$H$1:$H$15,0)). The part in red is the column containing E$11. The part in blue is the column containing 'Ref'.
    4. You can now put this I/M formula inside your own formula, like this:
    =IFERROR((INDEX($E$1:$E$15,MATCH("Ref",$H$1:$H$15,0))*'PAS TAL 1a'!I6*52/1000),"")

    If you sort one of the columns, then the 'Ref' will move with the sort, so that it will always find the row in column E which corresponds.



    Hope that helps. If something doesn't make sense, just ask!
    Regards,
    Aardigspook

    I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
    If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
    If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
    You don't need to give me rep if I helped, but a thank-you is nice.

  3. #3
    Registered User
    Join Date
    10-05-2018
    Location
    London
    MS-Off Ver
    2013
    Posts
    8

    Re: cant sort table differently without changing formula results

    yeah that's solved it thanks a lot

  4. #4
    Forum Expert
    Join Date
    03-20-2015
    Location
    Primarily UK, sometimes NL
    MS-Off Ver
    Work: Office 365 / Home: Office 2010
    Posts
    2,405

    Re: cant sort table differently without changing formula results

    You're welcome, glad I could help.

    As you've only recently joined, you may not know that you can mark the thread as Solved if your original question has been taken care of so others know there's an answer here. Instructions to do it are in my sig - if you could take a moment to do it, that would be appreciated. Thanks.

+ 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. need to sort three sheets differently in same workbook
    By sagikerius in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-23-2017, 01:51 PM
  2. [SOLVED] Pivot Table VBA: Results are not changing with code.
    By countryfan_nt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-03-2017, 04:13 AM
  3. Replies: 5
    Last Post: 05-09-2017, 08:48 AM
  4. Results keep changing after adding data table to sheet
    By jeroenv in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 08-03-2016, 10:08 AM
  5. Replies: 4
    Last Post: 11-20-2012, 06:00 PM
  6. [SOLVED] automatically sort a table after changing a cell
    By Aaron in forum Excel General
    Replies: 1
    Last Post: 07-26-2006, 01:30 PM
  7. [SOLVED] Changing the range of a table sort
    By RedHook in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-31-2006, 03:45 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