Vlookup with nested if's and variable range - excel

I've been trying to get a Vlookup to work more efficiently without VBA with I think is a dynamic (name) range, and without nested IF functions.
I'm new here and have tried to find the solution with other posts, but couldn't work it out.
I have one workbook with item codes and a vlookup, which references to another closed workbook (so function Indirect doesn't work) with cost values. In cell D3 there is a data validation cell where the user can select which sheet in the other workbook should be referenced (e.g. File001 or File002), changing the Vlookup and returning the correct cost.
Unfortunately I can't get it to work more efficiently.
I've tried Indirect, but that only works when the other workbook is open and I need it to be closed.
I'd like something simple such as:
=VLOOKUP(B3,INDIRECT("'[Book3.xlsx]" & D3 & "'!A3:B6"),2,FALSE)
which doesn't work
...and not what I use now, where it checks every time if it is File001, or 002, or 003,.. etc. and then vlookup:
=IFNA(IFS($K$2="","?",$K$2="File001",PROPER(VLOOKUP(UPPER($E13),NameRange001,4,FALSE)),$K$2="File0002",PROPER(VLOOKUP(UPPER($E13),NameRange002,4,FALSE)),$K$2="File003",PROPER(VLOOKUP(UPPER($E13),NameRange003,4,FALSE)),$K$2="File004",PROPER(VLOOKUP(UPPER($E13),NameRange004,4,FALSE)),$K$2="File005",PROPER(VLOOKUP(UPPER($E13),NameRange005,4,FALSE)),$K$2="File006",PROPER(VLOOKUP(UPPER($E13),NameRange006,4,FALSE))),"")
Code example:
I need to add more sheets from the other wb, so e.g. up to File0030, making the nested IFs extremely long. Does anyone please have an idea how to make this work more efficiently? I've been trying to improve this for maaany days.
Thanks in advance!!

Related

SUMIF in multiple sheets without using INDIRECT

Here is simplified EXCEL file I am working on.
Data sheet 1 called "first":
Data sheet 2 called "second":
Data structure and range (C2:E8) is same. I need to sum those sheets based on criteria in column B (Option).
Outcome I expect:
option1_sum sheet:
option2_sum sheet:
I can achieve this by putting either this formula in sum sheet C2 and dragging to E8:
=SUMIF(first!$B2,$B$2,first!C2)+SUMIF(second!$B2,$B$2,second!C2)
or this:
=IF(first!$B2=$B$2,first!C2,0)+IF(second!$B$2=$B2,second!C2,0)
These works as expected. Calculations are fast. The problem is that in original file there are ~100 data sheets to sum and area is more than 30000 cells in each sheet.
Formulas are getting very long and file is getting too heavy, takes ages to open.
If there wouldn't be IF condition I would calculate like this:
=sum(first:second!C2)
I expected SUMIF to work like this:
=SUMIF(first:second!$B2,$B$2,first:second!C2)
Unfortunately it doesn't. Every solution I've found uses INDIRECT formula like this:
=SUMPRODUCT(SUMIF(INDIRECT("'"&Sheetlist&"'!B2"),$B$2,INDIRECT("'"&Sheetlist&"'!C2"))) where Sheetlist is named list:
It does work, it is much shorter and makes file lighter more than 3 times, but because INDIRECT is volatile formula, it freezes excel for 5 seconds every time change is made in data sheets. And changes are made often.
Are there any other ways to make file lighter without losing speed?
Limitations:
Can't use VBA because it is stored in Sharepoint and accessed via both Excel 365 and browser Excel
Can't use manual recalculation as it is constantly monitored by several people and changes need to be seen on the spot
UPDATE: #JvdV suggested formula works, but after adding 10+ sheets every recalculations takes more than 5 seconds.
Updated said formula to include blank cells:
=LET(x,WRAPROWS(TOCOL(first:last!A1:E8,0),5),IFERROR(DROP(REDUCE(0,A2:A8,LAMBDA(a,b,VSTACK(a,BYCOL(FILTER(DROP(x,,2),(TAKE(x,,1)=b)*(INDEX(x,,2)=B2),0),LAMBDA(c,SUM(c)))))),1),0))
Using a custom function from the name manager comes to mind. Something like =TOCOL(GET.WORKBOOK(1)) would spill all sheetnames but it requires to save your workbook as .xlsm. So I came up with another idea. If your sheets are always in order you could do something like:
=WRAPROWS(TOCOL(first:last!A:E,1),5)
Now let's incorporate this into a REDUCE() to fill all cells in each sum-sheet:
Formula in C2:
=LET(x,WRAPROWS(TOCOL(first:last!A:E,1),5),IFERROR(DROP(REDUCE(0,A2:A8,LAMBDA(a,b,VSTACK(a,BYCOL(FILTER(DROP(x,,2),(TAKE(x,,1)=b)*(INDEX(x,,2)=B2),0),LAMBDA(c,SUM(c)))))),1),0))
Note that 'last' is just a placeholder for whatever is the last sheet in the sequence of sheets to sum from. I hope that below visual will help cover the basics of the theory implemented:

Excel: SEARCH function doesn't work with another worksheet

I am trying to compare a column of data (each row separately) to a column in another worksheet and give a simple TRUE/FALSE, I tried declaring the list directly in the SEARCH function but it didn't work so I resorted to TEXTJOIN to make it easier for the SEARCH function but it still does not work.
I tested the function below in Google Sheets and it worked, in Excel 2016 it just gives an error #NAME?
Any idea why or is there another way to do this? To clarify, SEARCH function is the one not working, not the ISNUMBER
=ISNUMBER(SEARCH(A2,TEXTJOIN(" ",TRUE,AnotherSheet!L3:L)))

How to convert text into formulas in Excel when referencing another worksheet?

I'm working on a set of worksheets where I need to make a summation with more than one constraint parameter, so I use the function sumifs ()
It happens that the worksheet needs to consider the rows that are added and so this sum with constraints is constructed from the function concatenate whose parameters come from another worksheet.
So, trying to use the suggestion did not work ... or with
Application.ThisCell.Parent.Evaluate (Ref)
So I need help since I don't know how to solve the issue, how to turn the text bellow into a formula:
=CONCATENATE("=SUMIFS(lançamentos!N$2:N";TEXT(L1+2;0);";lançamentos!AA$2:AA";TEXT(L1+2;0);";lançamentos!AA";TEXT(L1+4;0);";lançamentos!D2:D";TEXT(L1+2;0);";ADDRESS(ROW(A3);COLUMN(A3);4))")

Excel SUM COUNTIFS from different tables and futureproofing

I'm practising MS Excel skills. I have a workbook in which I want to analyses data from different tables.
Each worksheet contains a table with the information from the year. So in worksheet "2017" I have a table named "Table2017". I have this for each year (starting 2015).
After a some research, I finally found a way to count how many times something in a certain place happened.
=SUM(COUNTIFS(Table2018[Place];B3;Table2018[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2017[Place];B3;Table2017[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2016[Place];B3;Table2016[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2015[Place];B3;Table2015[Activity];{"Paid";"Awarded"}))
This works perfectly. It will calculate how many times per place a paid service or an awarded (gifted/sponsored) service was delivered. In the B column, I have a list of places (hence the B3 reference), so after completing the formula, I can select the cell and enlarge/drag to copy it to the rest of the column and apply for every place.
However, the formula is really long and every year upon creating a new worksheet, I need to add a new part to the formula.
Is there a way to compact this? And ideally have the formula search for every table that has the relevant information (like: "Table20??" or "Table 20*"), go in and count the times my conditions are found?
I hope my question is clear enough.
Thanks in advance!
P.S. I have zero experience in VBA/VBS, so I'm hoping to realize this in a normal formula.
There are ways to make it more compact, but they will necessarily make the function more complicated, so it wont be any easy win. See for yourself:
you basically need to be able to cycle through the years inside formula without creating custom formulas. One way to do this is to use ROW inside INDIRECT function. This way you can replace multiple
Table2015[Place]
with one array function containing
INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]")
as it is an array function it will essentially cycle through the cells in the ROW function creating Table2015[Place], Table2016[Place], Table2017[Place] and Table2018[Place]. Your whole formula would look something like this
=SUM(COUNTIFS(INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]");B3;INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Activity]");{"Paid";"Awarded"}))
and it must be entered using ctrl+shift+enter (you will see {} brackets around the function). This should work to make the function smaller and you will need only to change the cell reference each year instead of adding another sum, but the question is if the separate sums are not easier to read and maintain.

I have a worksheet that does not populate in certain cells or has errors (ie #DIV/0!), I think it is my function statement

I have a worksheet that does not populate in certain cells or has errors (i.e. #DIV/0!) I have validated the data is there on other ref tabs in the workbook but I believe the functions to be wrong, they work on some cells but not the others surrounding it. I have intermediate skills in excel and the functions being used are unfamiliar to me.
This the function that I am using:
=SUMPRODUCT(($A$2='ShippedQtyPrivate-Input'!$B$2:$B$818)*
('ShippedQtyPrivate-Input'!$A$2:$A$818=BR$2)*
($A16='ShippedQtyPrivate-Input'!$C$1:$H$1)*
('ShippedQtyPrivate-Input'!$C$2:$H$818))
But every 1st - 4th column after a populated column has no data. I don't understand why it doesn't work on all columns.
It depends how you want to handle the error. If you just want the cell to show the text 'Error' then the following should work:
=IFERROR(SUMPRODUCT(OFFSET(BM122,0,$G$1-8,1,8),OFFSET($BM$14,0,$G$1-8,1,8))/SUM(OFFSET($‌​BM$14,0,$G$1-8,1,8)),"Error")

Resources