Excel sort with formula in cell - excel

When I have a formula in a cell (the list is about 8,000 long, I go to try and sort it from most to least, however when I do this it will not sort, I believe it is because there is a formula in the cell, is doing it the normal way of clicking on the cell(s) and using the ribbon. Is there a special way of doing it when a formula is involved?
Thanks

Yes, by using absolute reference in your formulas, i.e. "$" for the rows. Since you are changing the order of the rows when you filter you need to make the reference static.
The table below is sorted by "Largest to smallest."
Another solution could be to copy the area and paste in a new sheet as "values"

Related

How to make an INDIRECT formula but with adjusting ranges

I'm hoping someone can help me make better use of the INDIRECT formula.
I have a list of sheet names in a table and an INDIRECT formula that uses that list to return a value in a specified cell - the list of sheet names is just an easier way for me to drag the formula down the table and read the appropriate cells without having to manually link each sheet.
=INDIRECT("'"&A2&"'!"&"K10")
This works fine for single cells as the range ref is simply stated as the text in the formula (K10), the problem arises when I need to start referring to a range such as K10:K15 and summing the values.
The range K10:K15 will inevitably have new rows added or deleted on the relative tab and as INDIRECT is using text as the reference it means the range doesn't automatically adjust - this is as I understand it one of the 'benefits' of INDIRECT but in this case is actually holding me back.
Also worth noting that the range (K10:K15) may move as rows are added/deleted above this, as this range is part of a larger table.
In simplistic terms I want to achieve the same result as a standard reference to a range on another sheet, e.g. =sum(sheet1!K10:K15) (as this will adjust when rows are added/deleted) but I just want to be able to dictate which sheet is referred to via a list I have in a table on a summary sheet.
How do I either write INDIRECT so the range adjusts when new rows are added/deleted or is there a different formula I should be using that achieves this?
Any advice greatly appreciated :)
=INDIRECT("'"&A2&"'!K"& MATCH(TRUE,INDIRECT("'"&A2&"'!K:K")<>"",0)&":K"&MAX((INDIRECT("'"&A2&"'!K:K")<>"")*(ROW(INDIRECT("'"&A2&"'!K:K")))))
This indirectly references the rows from the first non empty cell up to the last non empty cell in given sheet in column K. Not sure if you need to enter with ctrl + shift + enter (not in the app version).
Note: If the range contains empty cells in between the first and last non empty cell it will be included as value 0
Or in office 365 use the following:
=FILTER(INDIRECT("'"&A2&"'!K:K"),INDIRECT("'"&A2&"'!K:K")<>"")

Eliminating row gaps in excel

I have an excel datasheet with a column of 30 cells (A1:A30) that fills up automatically and randomly, so that some of the cells contain data and some don't.
I need to create a new list in the next column (b1:b30) containing only the data and no duplicates, but once the cells are filled I can't touch the datasheet so I can't use sorting, and sadly I work in an environment where macros aren't enabled so no VBA.
So far this is what I've come up with:
B1=IF(A1=0,IF(A2=0,...,IF(A29=0,A30,A29),A28),A27),...A2),A1)
And then
B2=IF(A1=OR(0,B1),IF(A2=OR(0,B1),...
And so on until by B30 I get an expression so horrifying it literally have me a nightmare.
It's there an easier way?
Thanks in advance
If you have access to the new Dynamic Array formulas UNIQUE and FILTER:
=UNIQUE(FILTER(A1:A30,A1:A30<>""))
Put that in B1 and Excel will spill down the list.
If one does not have access to those formula then put this in B1 and copy down:
=IFERROR(INDEX(A:A,AGGREGATE(15,7,ROW($A$1:$A$30)/(ROW($A$1:$A$30)=MATCH($A$1:$A$30,A:A,0)),ROW(A1))),"")

How to add formula to multiple cells with already existing values in them?

I have a table filled with hundreds of values in different cells (not coming in order, chaotic). Now I want to add 20% to each value (=x*1.2).
what formula should I use?
A quick way to get the desired result is to add a new table or worksheet and copy the update formula in each cell (e.g =A1*1.2). You could then overwrite the old values by pasting the new values. Pasting values overwrites any old formula.
If you want to manipulate the formula of every cell, you should look into a vba solution.
This is my solution:
1. Write a 1.2 in an empty cell out of table.
2. Copy this cell (1.2).
3. Select the table with values. Right-click of the mouse, select Paste Special -> Paste Special..-> Multiply. Voila!
Result: all selected values in the table were multiplied by 20%
Thanks a lot to my colleague Lina!

Excel Worksheet formulas that figure out the row it is on to use in cell reference calculations

I have a worksheet with a large number of tables. Every other table is formatted the same. Each row has set columns that will not change with regard to the formula. Say... =(A * B / G) - D
I'm trying to figure out a way to write a Worksheet formula that I can cut and paste without having to alter the row reference in the formula for it to work. That way I can copy and paste the formula into each table since I cannot click and drag it down the whole worksheet.
Ideally, I'd like to keep a list of formulas in a text file that I could just cut and past and not have to alter. I would be really cool if I could do something similar for using UDFs that can figure out the Range(Cells()) location on its own.
I'm using . Thanks!
=ROW()
but from your description I am not sure why you can not copy something like $A1 down and let the 1 update as it goes down each row. Take a look at what the effect of the $ symbol before the column or cell reference does. It prevents the column letter and/or row number from changing as cells are copied from one location to another.
ROW() will return the row number of what row it is in, or the row number of a reference if you supply the reference address:
ROW(AS134) will return 134.
To use this, you would most likely need to combine it with something like INDIRECT:
=INDIRECT("A"&ROW())
That formula would reference column A and the same row as wherever the formula was placed. HOWEVER, INDIRECT is a bad choice if you are using it frequently as its a volatile function and will recalculate anytime something on the worksheet changes. As per Scott Craner's suggestion, INDEX is a non volatile function so it will not force the recalculations and would look something like:
=INDEX(A:A,ROW())

How do I sort a table that is referenced by another table?

I have this table that is made from reference to other table.
and now I want to sort from small to largest the third column, but since it is referenced from another table is not sorting. And I also dont want excel to sort the reference table and I need the table to be referenced because I will change some values on the reference table and I need them to be connected, so I just cant copy and paste the values and then sort.
Could you give me some help?
Ok, I went ahead and built a small example:
The formulas are as follows:
The 3 in Row 20 are to be copied downwards with PasteSpecial>Formulas:
in E20: =IFERROR(RANK($D20,$D$20:$D$33,1),"")
in F20: =IF(ISNUMBER($D20),"",(COUNTIF($D$20:$D$33,"<"&$D20)+1)+COUNTIF($D$20:$D20,$D20)-1)
in G20: =IF($E20="",(MAX($E$20:$E$33)+$F20),$E20)
The formula in B3 is to be copied into the whole target table with PasteSpecial>Formulas:
in B2: =INDEX(B$20:B$33,MATCH(ROW()-1,$G$20:$G$33,0),1)
Please let me know if you have any questions!
This method only works if the entries in the column you are sorting on are unique. You will need to adjust the address ranges to suit your data.
The formulas in the each column start from X and finishing in Z as you move left are as follows:
=INDEX($X$41:$X$47,MATCH(ROWS($Z$29:Z29),COUNTIF($Z$41:$Z$47,"<="&$Z$41:$Z$47),0))
=INDEX($Y$41:$Y$47,MATCH(ROWS($Z$29:Z29),COUNTIF($Z$41:$Z$47,"<="&$Z$41:$Z$47),0))
=INDEX($Z$41:$Z$47,MATCH(ROWS($Z$29:Z29),COUNTIF($Z$41:$Z$47,"<="&$Z$41:$Z$47),0))
Note only the range right after INDEX is changing. Thes are CSE or array formulas. It means you need to press CONTROL+SHIFT+ENTER when you are done editing your cell. Then copy the individual cell and paste it in the rows below the copied cell. pasting including the source cell or dragging down MAY not work. Repeat this for all three columns.
Proof of concept

Resources