How to make a VLOOKUP formula conditional in Excel? - excel

I've got a large Excel workbook with multiple worksheets and copious amounts of data. Every third sheet is an amalgam of the previous two sets. I've set up the following formula to pull the data from each worksheet, add it together, and present it in the third worksheet:
=SUM(VLOOKUP($A7,'worksheet 1'!$A:$F,2,FALSE)+VLOOKUP($A7,'worksheet 2'!$A:$F,2,FALSE))
This works as expected, unless the column A value is in one of the source worksheets but not the other. Then, I get the #N/A error with "Value not available."
What I want to do is make it so that, if the column A value is not present in the first worksheet, excel ignores that VLOOKUP request and simply pulls in the data from the second worksheet (and vice-versa for a value in the #2 but not #1).
If VLOOKUP isn't the appropriate tool to use, I can change it. I had an example sheet that I used to build this query, and that's how they put it together.
I am not an Excel expert and I've never used Access, so I'm learning as I go. Any assistance is appreciated!

Since you are using numbers, you could actually use multiple sumif statements.
I would suggest something like:
=SUM(SUMIF('worksheet 1'!$A:$A,$A7,'worksheet 1'!$B:$B), SUMIF('worksheet 2'!$A:$A,$A7,'worksheet 2'!$B:$B))
SUMIF is faster, won't look in the entire range, and if it does not find the value in A7, it will simply return 0.
I hope this helps.
UPDATE
Simple example. Say we have 2 sheets with a total column and we would like to get the value of that total cell:
you could sum 2 VLOOKUP forumale, or you could use SUMIF as follows:
=SUM(SUMIF(Sheet1!$A:$A,$A$7,Sheet1!$B:$B),SUMIF(Sheet2!$A:$A,$A$7,Sheet2!$B:$B))
The above is simply saying: Look for the value in cell A7 in the range $A:$A in sheet1 and return what's in the same row in the range $B:$B, and do the same in sheet2, then sum them both.
Note that SUMIF will actually sum all the resutls in a range, so if you have 2 totals in Sheet1!$A:$A then it will sum them both up. In a way this is the opposite of what VLOOKUP will do: it will stop once the first row containing the value is found. SUMIF won't stop.
The desired result in the example above is 208 and that's what you shall get.

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")<>"")

Copy the Excel RANK formula without changing the end reference

Suppose I have a simple spreadsheet with 3 rows of data that I want to rank in separate columns. The example I will use is simple, but my actual dataset is 12k + rows. In this simple example, I want to use the RANK formula from Excel to do this. To rank the values in column Police, I'll use the formula =RANK(B2, B2:B11, 1), with B2:B11 being the range.
As I mentioned, my actual dataset has thousands of rows and many more columns to compare. Even in this example, I want a simple way to copy the formula to all of the other _RANK column cells. If I simply copy the cell to the other cells, +1 gets added to the cell value. This is what I want to happen, EXCEPT for the ending cell of the range.
As you can see above, this is incorrect. The formula gets set to =RANK(B11,B11:B20,1) for cell E11, when what I want is =RANK(B11,B11:B11,1). How can I easily copy this formula across multiple cells so that it is has the correct formula?
Placing $ before the cell references makes it static. Try changing your formula to Rank(B11, B$2:B$20,1). Coping this formula will only change those references which are not proceeded with $.

Using SUMIF function and the range and [sum_range] change with every cell

I have looked for this answer but haven't found anything that has worked so I apologize if this is a duplicate question.
I am using Excel 2010 and have two sheets within one workbook. The first sheet holds the majority of information regarding individual members and is where I am using the formula. The second sheet holds data regarding each members' usage. Each line represents one individual. I am trying to gather all of the instances for one individual listed in sheet two and place it in a cell in sheet one.
I have used the sumif function which works perfectly for the first individual I use it on. After that, dragging the box changes both the range and sum_range of the formula along with the criteria. I want the criteria to change to the cell in the next row but I need the range and the sum_range to remain the same for every cell. If I copy the formula from the first cell and paste it into the second row, nothing changes.
Any ideas as to how I can make the sumif formula work over the entire column without changing the range and sum_range? Or is there an easier way to do this? Please keep in mind, the second sheet will expand over time to include more and more instances which will need to be included in future calculations.
Lets say your range is A1:A3 so to completely lock it just change it into $A$1:$A$3.

excel 2010, look up blank cells in two columns, return text in corresponding different column

Here is a screenshot of my data:
I want to search B4:B40 and C4:C40 and find all cells that are blank for both specified ranges. If blank in both ranges, return the text in the corresponding row in column A. Ideally, the output could be combined and it could list something like 8:00-2:00.
here is what i have so far:
=INDEX('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!B4:B40, MATCH("",'C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!B4:B40,0),'C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!B2)
Am I on the right path?
The formula you want is:
=IFERROR(INDEX($A$18:$A$40,AGGREGATE(15,6,(ROW($A$18:$A$40)-ROW($A$18)+1)/(($B$18:$B$40="")*($C$18:$C$40="")),ROW(1:1))),"")
I will let you put in the workbook and sheet references. They are only needed on the Ranges. Do not put them on the Range references in the the ROW() functions. They are only there to return a number and it does not matter the sheet to which they reference. Just make sure that the ranges themselves match.
The concatenation with the workbook references would make the formula long and unwieldy. To do that VBA would be the best route.
Edit:
Got bored and decide to put in your workbook and worksheet references:
=IFERROR(INDEX('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!$A$4:$A$40,AGGREGATE(15,6,(ROW($A$4:$A$40)-ROW($A$4)+1)/(('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!$B$4:$B$40="")*('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!$C$4:$C$40="")),ROW(1:1))),"")
Do you want all the values in a single cell or in a new column?
=IF(AND(ISBLANK(B18), ISBLANK(C18)), A18, "")
Assuming your data starts in A18 (as per the screenshot), you can put this in cell D18 and copy all the way down.

Count the numbers of projects

I have two worksheets; Sheet1 contains different building names (repetition) and Sheet2 contains a list of the building names. I will like to count the number of building in sheet1 and show them in sheet2.
Currently, I'm using workbook function COUNTIF. How can i do it if there's a new building added in sheet1? (VBA or workbook function is fine)
You could create a dynamic named range in sheet 1 (for the list of buildings), and then refer to the named range in your countif function in sheet2.
For more details on how dynamic named ranges work, have a look at this:-
http://www.ozgrid.com/Excel/DynamicRanges.htm
Another alternative would be to use the whole column that contains the building names, as your countif function will only return a value for cells that contain the criteria specified in the function. It might look something like this:-
=countif(Sheet1!A:A,"building a") <--this would search for all cells containing 'building a' in column A of Sheet 1
As you use either dynamic range or A:A range on CounIF() it works only as long as you do not have any blank cells within the range. Please know that. In such cases you are better off with a pivot table and pointing to pivot table's total cells accordingly.
Or if you still prefer to use CountIf() in blank cells case, you may apply conditional formatting to fill the blanks with some text/string. Don't forget conditional formatting contributes to slowing down your sheet performance. Or you could wrap CountIf() with an IF condition.

Resources