=IFERROR(IF((INDEX(named range1,MATCH(named range2&A1,named range3,0)))<>"",INDEX(named range1,MATCH(named range2&A1,named range3,0)),"-"),"")
Here in this formula I am trying to vertical lookup a value using index-match and checking it within a if statement for blank value.If it is not blank I am using the non-blank value to set it in a given cell.
How can I optimise my formula to reduce performance overhead in excel.
I don't want to use vba for this by storing the result in a variable
The most time consuming bit is the Match(), so avoiding a duplication of the same Match is key. You can
place the Index/Match in a helper cell and then use the formula
=IFERROR(IF(B1<>"",B1,"-"),"")
This way the Index/Match will be calculated only once.
place the Match into a named formula. If you keep your wits about you, named formulas can work with relative cell references. Select the cell where you want the formula to go, then create a named range "NamedRange4" with the formula
=MATCH(named range2&A1,named range3,0)
Then use this formula in the selected cell:
=IFERROR(IF((INDEX(named range1,NamedRange4))<>"",INDEX(named range1,NamedRange4),"-"),"")
The Match will be calculated only once and the result stored in the named range. With relative cell referencing of NamedRange4, the IfError formula can be used in other cells with correct results.
Related
I have a pile of data on Sheet1
I have a SUMIFS formula on Sheet2
The columns I am summing are named NETPERD1, NETPERD2, NETPERD3.....NETPERD12
I want to write the SUMIFS so that I can easily change which column I am summing.
On Sheet2, in cell $C$4, I will enter NETPERD1 or NETPERD2 etc. and I want my SUMIF to determine which column it should sum.
I think I should be able to do this with IndexMatch but I can't get it to work.
Here is my SUMIFS that works.
I want to replace NETPERD1 with $C$4
=SUMIFS(Sheet1!NETPERD1,Sheet1!ACCTGRPCOD,Perplas!$A15,Sheet1!AUDTORG,Perplas!C$1,Sheet1!FSCSDSG,Perplas!C$2,Sheet1!FSCSYR,Perplas!C$3)
If your named ranges span the entire column, then for the INDEX/MATCH try:
=SUMIFS(INDEX(Sheet1!$A:$Z,,Match(Perplas!C$4,Sheet1!A$1:Z$1,0)),...
changing the Z to your rightmost column.
Try using the indirect function. You can supply indirect with a character string that Excel then reads as part of a cell/range reference.
Working off the code you shared + the fact that you said that you'll put in the name of the range in cell C4:
=SUMIFS(INDIRECT("Sheet1!"&$C$4),Sheet1!ACCTGRPCOD,Perplas!$A15,Sheet1!AUDTORG,Perplas!C$1,Sheet1!FSCSDSG,Perplas!C$2,Sheet1!FSCSYR,Perplas!C$3)
I think that should work? I'm a little confused about how you're able to reference the row name without a named range, so that might cause a wrinkle in this.
This phrase is embedded in many formulas on my sheet:
OFFSET(Table1[ReportDate],0,$B$1)
It returns a reference to a column in Table1.
To make those many formulas shorter, I'd like to extract this OFFSET formula to a separate cell for the others to refer to.
The OFFSET returns a reference. Putting OFFSET(…) in a cell just returns #VALUE, and so does INDIRECT(OFFSET(…)).
EDIT: The "many formulas" are SUMIFS, and the OFFSET chooses the column to be summed:
=SUMIFS(OFFSET(Table1[ReportDate],0,$B$1),Table1[ColumnB],$H10,Table1[Report Date],"<="&rYesterday)
If I understand you correctly, you want to replace the original OFFSET formula with something simpler to be used in other formulas.
You can do so by giving a name to this OFFSET formula.
In the above mock-up example, I have given a name SUM_Rng for the OFFSET formula and used it in my second formula, which is the same as your original SUMIFS formula.
You can press Ctrl+F3 to bring out the Name Manager in Excel and add or modify names which can represent a reference of a cell or a range either hard-coded or returned by a formula. I noticed that you already used a name rYesterday in your SUMIFS formula so there should be no problem for you to add this formula to the name manager.
Cheers :)
It's probably a simple problem, but I did not even know the keywords to google it ;/. Let's say I have this data :
Now I also have this litle formula:
If I know drag the C cell to the right, Excel will attempt the following caluclation:
=2+B1
What I want him to do is to attempt this calculation
=2+A2
Of course the easiest solution would be to store my initial data in one row instead of 1 column, but it is really inconvenient for me. Thanks for any help
You can use the indirect() method to reference a cell by it's "String identifier", i.e. "A3". When filling out to the right, use CONCATENATE() and COLUMN() to create your String identifiers {A1,A2,A3,A4,A5...} as required:
=2+INDIRECT(CONCATENATE("A";COLUMN()-2))
This will result in the following:
Side-Node: If you want this for some x/y-Grid-Generation, you can also be lazy,
and just insert =COLUMN() for every cell from "A1 - Z1" and ROW() for every cell from "A2 - A24".
(Or even avoid these at all and directly perform your actual calculation by using column() and row() as replacement for your x/y.
You may try using a combination of the INDIRECT and COLUMN functions:
=2+INDIRECT("A"&(COLUMN()-2))
You would paste the above formula into cell C1, and then drag across to the right however many columns/rows you wanted to cover.
This would result in the following:
This works because COLUMN()-2 returns 1 for the C column, 2 for the D column, and so on. Therefore, the formula will be calling INDIRECT on A1, A2, etc. for column C, D, and so on.
In general, if you want relative references to move down as cells are dragged to the right, you can use this:
Instead of:
= 2+A1
Do:
= 2+INDEX($A:$A,COLUMN()+<offset>)
Where <offset> is whatever offset you need. The offset will change depending on which column the starting formula is located in.
INDEX should be preferred over INDIRECT because INDIRECT is volatile (must recalculate after any change to the workbook) but INDEX is not (only recalculated when one of the inputs the formula, in this case $A:$A, changes).
I have a SUMIFS formula with which I am trying to build a dynamic range in order to avoid a circular reference. As it must search and sum through all the range, it must not consider the line where the formula is placed.
Sheet - Example
So I wrote this formula:
SUMIFS((C1:ADDRESS(VALUE(ROW(C6))-1;COLUMN(C1));ADDRESS(VALUE(ROW(C6))+1;COLUMN(C1)):ADDRESS(COUNTA(C:C);COLUMN(C1)));(C1:ADDRESS(VALUE(ROW(C6))-1;COLUMN(A1));ADDRESS(VALUE(ROW(C6))+1;COLUMN(A1)):ADDRESS(COUNTA(C:C);COLUMN(A1)));A6;(B1:ADDRESS(VALUE(ROW(C6))-1;COLUMN(B1));ADDRESS(VALUE(ROW(C6))+1;COLUMN(B1)):ADDRESS(COUNTA(C:C);COLUMN(B1)));"X")
However, after the sum_range it doesn't recognize the cell references. It remains "black". I tried another formula with OFFSET but got the same issue.
Any ideia what is going on?
A quick note, I need a dynamic range because there might be new lines inserted afterwards or people might apply filters, so I cannot use a normal reference.
You cannot have the formula in the same column as the range to sum, in this case it would cause a circular reference.
Use INDEX and two SUMIFS, SUMIFS does not like disjointed ranges and ADDRESS/OFFSET/INDIRECT are volatile:
=SUMIFS($C$1:INDEX(C:C;ROW()-1);$A$1:INDEX(A:A;ROW()-1);A2;$B$1:INDEX(B:B;ROW()-1);B2)+SUMIFS(INDEX(C:C;ROW()+1):INDEX(C:C;MATCH(1E+99;C:C));INDEX(A:A;ROW()+1):INDEX(A:A;MATCH(1E+99;C:C));A2;INDEX(B:B;ROW()+1):INDEX(B:B;MATCH(1E+99;C:C));B2)
I have a code that loops through and calculates a formula for a column of inputs for a row of dates. It is rather slow looping and writing in VBA so I was hoping to instead paste the formula in the cells instead of the computed value. My plan is to create a range for the results and set the range equal to the formula.
However I am stuck with the formula. The formula uses the previous answer plus other data and I am stuck trying to create the formula for the range so the reference cells move for each cell in the range.
The formula will look like this for cell N7
=IF(M7<>0,(M7-$D7)^(1/30.4),$B7*(1-$C7)^(1/$E7))
The formula will look like this when copied to cell O7
=IF(N7<>0,(N7-$D7)^(1/30.4),$B7*(1-$C7)^(1/$E7))
For O8 it would look like this
=IF(N8<>0,(N8-$D8)^(1/30.4),$B8*(1-$C8)^(1/$E8))
I understand how to loop through each cell and write the formula, but I don't think it would be much faster than calculating it and then writing the answer. I was hoping there is a way to set the range equal to a formula that would populate the correct cell references.
Would ActiveCell.Offset be a solution?
Use relative references:
.FormulaR1C1 = "=IF(RC[-1]<>0,(RC[-1]-RC4)^(1/30.4),RC2*(1-RC3)^(1/RC5))"
You can use this on a range to populate in one go if you need rather than looping through with something like this:
Range("N7:P20").FormulaR1C1 = "=IF(RC[-1]<>0,(RC[-1]-RC4)^(1/30.4),RC2*(1-RC3)^(1/RC5))"
R is row and C is column relative to self negatives have to be in []
You can also do this by using A1 Notation.
Range("N7:O8").Formula = "=IF(M7<>0,(M7-$D7)^(1/30.4),$B7*(1-$C7)^(1/$E7))"
There are advantages using R1C1 Notation but for this one, you better off using this, easier to read. HTH.