Cell Referencing Formula - excel

Was using this formula SheetName!CellAddress
I need to import Data that is available on other 2 sheets namely (sheet2 and sheet3) into sheet 1 in a way such that
the row values will be alternate i.e one value from sheet 2 and other value from sheet 3 respectively
Have tried like this
=Sheet2!C2
=Sheet3!D2
when i dragged for other values i was get only values in the even cell like(c4,d4,c6,d6)
If i change the for formula to
=Sheet2!C1
=Sheet3!D1
i was get only values in the even cell like(c3,d3,c5,d5)
But what i need is continous cells in row( c1,d1,c2,d2,c3,d3...)
So what formula i need to use for getting this result

I am still not 100% clear on what the question is asking, so let me know if the below answer doesn't work for you.
It sounds like what you're looking for can be accomplished with OFFSET and clever use of IF statement.
Suppose your formulas will be in column A, starting in A2. Then enter the following formula into A2 (line split added for readability; remove it):
= IF(MOD(COUNTA(A$1:A1),2)=0, OFFSET(Sheet2!$C$1, COUNTA(A$1:A1) / 2, 0),
OFFSET(Sheet3!$D$1, COUNTA(A$1:A1) / 2, 0))
Then drag the formula down.
What it does:
MOD(COUNTA(A$1:A1),2)=0 - checks whether we're in odd row or even row.
COUNTA(A$1:A1)/ 2 - takes half of the number of non-empty cells immediately above the current cell.
OFFSET(Sheet2!$C$1, COUNTA(A$1:A1) / 2, 0) - takes the cell which is COUNTA(A$1:A1)/ 2 cells below Sheet2!$C$1.

Here's a fairly basic method:
Enter the first two formulas as Text - you can either do this by formatting the cell number as text or preceding the formula by an apostrophe.
Select cells and fill down to get:
=Sheet2!C2
=Sheet3!D2
=Sheet2!C3
=Sheet3!D3
=Sheet2!C4
=Sheet3!D4
...
Select the column and choose Data|Text to Columns|Finish to change text to values.

Related

finding next empty row

This might be easy for many but I need to solve an issue which is following;
I have the following formula which finds the empty row after D4.
=MATCH(TRUE;D4:D1048576="";0)+3
After this I want to be able to find the empty row from another defined cell, say D10.
How can I do this?
Try this as an array formula - Ctrl+Shift+Enter:
=MIN(IF(D4:D100="",ROW(D4:D100)))
It works from D4 to D100, providing the first empty value.
If you're looking to use same formula to match next cell then use
For blanks after D4
=MATCH(TRUE,INDEX(ISBLANK(D4:D1048576),0),0)
For blanks after D10
=MATCH(TRUE,INDEX(ISBLANK(D10:D1048576),0),0)
To find the A1th blank cell, you can use the following formula:
=AGGREGATE(15,6,ROW(D:D)/--ISBLANK(D:D),A1)
How it works
AGGREGATE(15,6,..) is like SMALL(..), but skips any error values.
ROW(..) provides the row number of the cell provided
ISBLANK(..) is TRUE for blank cells or FALSE for non-blank cells
-- converts TRUE to 1 and FALSE to 0. This means that ROW(D:D)/--ISBLANK(D:D) will be either the Row Number (for blank cells) or a #Div0! error (which AGGREGATE will skip)
This produces a list of row numbers for all the blank cells, and you then use the AGGREGATE function to get the kth item in that list.
Taking it a step further
So, you want the 1st item larger than a specific row. We change the last argument in AGGREGATE to 1, and swap change our "Error out" code from ISBLANK(D:D) to AND(ISBLANK(D:D), ROW(D:D)>A1), to get the first blank row after the row number stored in A1:
=AGGREGATE(15, 6, ROW(D:D)/--AND(ISBLANK(D:D), ROW(D:D)>A1), 1)

Syntax: Applying IF to a cell range in Excel

I've been trying to write a formula to summarise in one cell the presence/ absence of certain values in a different range of of cells in Excel
So in the one table and worksheet, I wrote
=IF(B1:F1=1,1,0) Formula 1
which is supposed to mean
If any of the values in cells B1:F1 are equal to 1, then note 1, otherwise not 0.
But somehow the syntax isn't working.
I've applied "" and ; and brackets right left and centre, but to no avail.
I'm pretty sure I done this before and it was pretty simple when I hit upon the right synstax, but the how and where fell through the colander which is my brain today :-?
Additionally I will want to ask the formula to apply another condition to the output cell which is
=if (A1 = value n or certain values, 1, 0) Formula2
Column A has numerically coded ordinal values 0-9, so an aexample of teh 1 conditions might be any of values 1, 2 or 9 in column, should produce a 1 in the result cell in which Formula 1 and 2 will be written.
So the result cell would contain somelike
=Formula1_or_Formula2_contain_certain_values, 1, 0) Formula 3
Obviously the systax of Formulas 2 and 3 is awol, but I write to demonostrate the formulae intended purposes.
The easiest way to make the first formula is like this:
=IF(SUM(B1:E1)>0,1,0)
No arrays, no problems :)

Excel Formula with IF... ELSE

Hi all,
I have this excel where by I need to find the location of the item if they are found in column B.
So In my F column, I tried to write ifelse formula which didnt work.which is
=IF(D2="NULL","NONE",C((D2))).
My idea is if D2 is not null, use the value in D column to find the location in C column. In this example, fish no 4, so it is found, my F column should show the value "C" using the value shown in D column and use it as Row no in C column
I hope you guys get the idea and help me out a newbie in excel. Thanks in advance
=vlookup($D2,$A$2:$C$6,3,0)
you can use that in column F. Place that formula in F2 and copy down.
you could technically use it in column E as well, but you would need to change the 3 to a 2.
you did not say what you wanted to do if the D value was "Null" so I am going to take a stab at the dark and wrap you lookup formula in an if statement that will deal with "Null" or empty cells
=IF(OR($D2="NULL",$D2=""),"",VLOOKUP($D2,$A$2:$C$6,3,0))
That is the alternative formula to place in F2 and copy down.
Use the formula:
=IF(D2<>"NULL",VLOOKUP(D2,A2:C6,3,FALSE),"Value is NULL")
Here is the working example:
Put formula in cell F2 and drag it down.
[edit]to pull proper location column, not just the row #[/edit]
Seems like a job for MATCH+OFFSET
Try this formula in cell F2:
=OFFSET($C$1, MATCH(E2,B:B,0)-1, 0, 1, 1)
Match is used to locate the value in the first argument (ie E2) within the range specified in 2nd argument (ie B:B). I use B:B but you could also use range B2:B30 or whatever more specific range you want. (I prefer the more generic B:B, though :) )
Third paramter "0" just indicates "Exact match".
This function will retun "#N/A" if nothing found.
OFFSET takes the result from MATCH to pick out the Location you want. The first parameter in OFFSET is the rows below (or above if negative) from the base row (in this case $C$1). the next is the column: 0 since we're in the column we want to be in. The last two are the size of the range: 1,1 is a 1x1 cell, so just 1 cell. If we did ...,2,3), that would be 2 rows high and 3 columns wide - or a 6 cell range. We're just after 1 cell here.
I've always preferred MATCH + OFFSET to other options, I just found they held up more robustly to changes in a sheet (ie new rows/columns added). So it's mostly personaly preference over VLOOKUP and INDEX. I honestly have never compared their actual performance, however, I've never had any issues with MATCH+OFFSET running slowly :)

Is there a 2 Value Look up function in MS Excel that can perform the following?

I am going crazy over this. It seems so simple yet I can't figure this out. I have two worksheets. First worksheet is my data. Second is like an answer key. Upon checking checking, A1:B1 in Sheet 1 is a match with the conditions in Row 52 in SHEET 2, therefore, the value in Column C is "MGC". What is the formula that will perform this function? It's really hard to explain without the data so I pasted a link of the sample spreadsheet. Thank you so much in advance.
sample spreadsheet here. https://docs.google.com/spreadsheets/d/1_AjuNfCdGfEM-XkqPa6W4hSIxQg4NM2Vg4c2C1pQ_vQ/edit?usp=sharing
screenshot here. (wont let me post i have no reputation)
In Sheet2, insert a column in front of Column A and put the formula in A2 =C2&D2.
Then in Sheet1, Cell C2 the formula =vlookup(A2&B2,Sheet2!A:B,2,0).
the first make a concatenated key to lookup, then the second looks up that key.
How about a index(match())? If I've understood correctly you need to match across both the A and B column in sheet one, checking for the relevant values in B and C on sheet 2 to retrun worksheet 2 column a to worksheet 1 column c.
third version try:
=INDEX(Sheet2!$C$1:$C$360,MATCH(Sheet1!A1&Sheet1!B1,Sheet2!$B$1:$B$360&Sheet2!$C$1:$C$360,0))
Basically what this does is use concatenation, the & operator, to specify you are looking for "Criteria A" & "Criteria B" in sheet 1, which makes the string "Criteria A Criteria B", which is supplied in the first part of the match function.
In the second it then says match this against all of my variables in sheet 2 in the same way with concantenation.
The final part of match function (0) specifies you want an 'exact' match
It then supplied this as a reference to the index function, which then finds the row intersecting with the value you want, and returns that.
As noted here https://support.microsoft.com/en-us/kb/59482 this is an array formula, so it behaves differently, and must be input differently. https://support.office.com/en-za/article/Guidelines-and-examples-of-array-formulas-7d94a64e-3ff3-4686-9372-ecfd5caa57c7
There are (at least) 2 ways you could do this without VBA.
USING A SORTED LIST
The first relies on the assumption that your data can be re-sorted, so that everything "Unreported" is in the top, and everything "reported" is together below that (or vice versa). Assuming that this is the case (and it appears to already be sorted like this),we will use the function OFFSET to create a new range which shows only the values that align with either being "Unreported" or "Reported".
Offset takes a given reference to a point on a sheet, and then moves down/up & left/right to see what reference you want to return. Then, it returns a range of cells of a given height, and a given width. Here, we will want to start on Sheet2 at the top left, moving down until we find the term "Unreported" or "Reported". Once that term is found, we will want to move one column to the right (to pull column B from sheet 2), and then have a 'height' of as many rows as there are "unreported" or "reported" cells. This will look as follows in A1 on sheet 1, copied down:
=OFFSET(Sheet2!$A$1,MATCH(A1,Sheet2!A:A,0)-1,1,COUNTIF(Sheet2!A:A,A1),1)
This says: First, start at cell A1 on sheet2. Then find the term in A1 (either "unreported" or "reported", on sheet2!A:A (we subtract 1 because OFFSET starts at A1 - so if your data starts at A1 we need to actually stay at "0". If you have headers on sheet2, you will not need this -1). Then, move 1 column to the right. Go down the rows for as many times as Sheet2 column A has the term found in Sheet1 A1. Stay 1 column wide. Together, this will leave you with a single range on sheet2, showing column B for the entire length that column A matches your term in sheet1 A1.
Now we need to take that OFFSET, and use it to find out when the term in Sheet1 B1 is matched in Sheet2 column B. This will work as follows:
=MATCH(B1,[FORMULA ABOVE],0)
This shows the number of rows down, starting at the special OFFSET array created above, that the term from B1 is matched in column B from sheet2. To use this information to pull the result from column C on sheet 2, we can use the INDEX function, like so:
=INDEX([FORMULA ABOVE],MATCH(B1,[FORMULA ABOVE],0))
Because this would be fairly convoluted to have in a single cell, we can simplify this by using VLOOKUP, which will only require the OFFSET function to be entered a single time. This will work as follows:
=VLOOKUP(B1,[FORMULA ABOVE],2,0)
This takes the OFFSET formula above, finds the matching term in B1, and moves to the 2nd column to get the value from column C in sheet2. Because we are going to use VLOOKUP, the offset formula above will need to be adjusted to provide 2 columns of data instead of 1. Together, this will look as follows:
FINAL FORMULA FOR SHEET1, C1 & COPIED DOWN
=VLOOKUP(B1,OFFSET(Sheet2!$A$1,MATCH(A1,Sheet2!A:A,0)-1,1,COUNTIF(Sheet2!A:A,A1),2),2,0)
OPTION USING ARRAY FORMULAS
The above method will only work if your data is sorted so that the REPORTED and UNREPORTED rows are grouped together. If they cannot be sorted, you can use an ARRAY FORMULA, which essentially takes a formula which would normal apply to a single cell, and runs it over an entire range of cells. It returns an array of results, which must be reduced down to a single value. A basic array formula looks like this [assume for this example that A1 = 1, A2 = 2...A5 = 5]:
=IF(A1:A5>3,A1:A5,"")
Confirm this (and all array functions) by pressing CTRL + SHIFT + ENTER, instead of just ENTER. This looks at each cell from A1:A5, and if the value is bigger than 3, it gives the number from that cell - otherwise, it returns "". In this case, the result would be the array {"";"";"";4;5}. To get the single total of 9, wrap that in a SUM function:
=SUM(IF(A1:A5>3,A1:A5,""))
In your case, we will want to use an array formula to see what row in Sheet2 matches A1 from Sheet1, and B1 from Sheet1. This will look like this:
=IF(Sheet2!$A$1:A$100=A1,IF(Sheet2!$B$1:$B$100,ROW($B$1:$B$100),""),"")
This checks which rows in column A from sheet 2 match A1. For those that do, it then checks which rows in column B from sheet 2 match B1. For those, it pulls the row number from that match. Everything else returns "". Assuming no duplicates, there should only 1 row number which gets returned. To pull that number from the array of results, wrap the whole thing in a MATCH function. Now that you have the row number, you can use an INDEX function to pull the result in Column C with that row, like this:
FINAL ARRAY FORMULA METHOD
=INDEX($C$1:$C$100,MAX(IF(Sheet2!$A$1:A$100=A1,IF(Sheet2!$B$1:$B$100,ROW(Sheet2!$B$1:$B$100),""),"")))
Remember to confirm with CTRL + SHIFT + ENTER instead of just ENTER, when you type this formula. Note that I didn't refer to all of Sheet2!A:A, because array formulas run very slowly over large ranges.
The following formula should work without making any changes to the datasheets.
=INDEX(Sheet2!$A$1:$A$360,MATCH(Sheet1!A1,IF(Sheet2!$C$1:$C$360=Sheet1!B1,Sheet2!$B$1:$B$360),0))
Remember to save this formula as an array with CTRL+SHIFT+ENTER
Documentation on how to use INDEX and MATCH against multiple criteria can be found on Microsoft Support.
It's not clear what you want to do with the multiples that do not have corresponding matches. txed is listed as Unreported twice in Sheet1; kntyctap is listed as Unreported three times. There are only one corresponding match on Sheet2 for each of these.
Non-array Standard Formulas for multiple criteria matches
For Excel 2010 and above use this standard formula in Sheet1!C1:
=IFERROR(INDEX(Sheet2!$A$1:$A$999,AGGREGATE(15,6,ROW(1:999)/((Sheet2!$B$1:$B$999=A2)*(Sheet2!$C$1:$C$999=B1)), COUNTIFS(A$1:A1, A1, B$1:B1, B1))), "")
For version of Excel prior to 2010 use this standard formula in Sheet1!C1:
=IFERROR(INDEX(Sheet2!$A$1:$A$999, SMALL(INDEX(ROW($1:$999)+((Sheet2!$B$1:$B$999<>A1)+(Sheet2!$C$1:$C$999<>B1))*1E+99, , ), COUNTIFS(A$1:A1, A1, B$1:B1, B1))), "")
I've handled error with the IFERROR function in that latter formula. Excel 2003 and previous may have to use an IF(ISERROR(..., ...)) combination.

Sum cells values with a separation of 3 columns in Excel

I would like to create a formula that sums all the values that I'm going to add in the future in some cells of the same row. For example, I would like to add cells D3,G3,J3,M3 and so on (separated 3 rows) in cell D1.
Best regards,
A good solution will depend on what (if anything) is in the intervening columns on row 3. A SUMPRODUCT function can produce some nice results by checking the stagger or offset of the columns but it isn't going to like text put into the intervening cells.
=SUMPRODUCT((INDEX(3:3, 1, 4):INDEX(3:3, 1, MATCH(1E+99,3:3 )))*NOT(MOD(COLUMN(INDEX(3:3, 1, 4):INDEX(3:3, 1, MATCH(1E+99,3:3 )))-1, 3)))
By switching to an array formula and a condition SUM function, you should be able to happily skip over any text values.
=SUM(IF(NOT(MOD(COLUMN(INDEX(3:3,1,4):INDEX(3:3,1,MATCH(E1+99,3:3)))-1,3)),INDEX(3:3,1,4):INDEX(3:3,1,MATCH(E1+99,3:3))))
Array formulas need to be finalized with Ctrl+Shift+Enter↵.
If neither ot those fits the bill, provide a little more information on the nature of what not to sum and more help can be offered.
This will do the job:
1) put =SUM(D2:XFD2) in cell D1
2) put =IF(MOD(COLUMN(D3)+2,3)=0,IF(D3="","",D3),"") in all cells from (D2 .. til the end)
3) put your data in D3 .... til the end.
Anonymous' solution works if you only need to sum one row. If you need to be able to drag that formula down, consider using a flag in row 2 to identify every 3rd column (like Anonymous did) , and use a sumif formula to add the columns where that flag is present.
Type
=
in the cell where your first result will appear (e.g. D1).
Click on the first value in the first row.
Press + on numpad.
Click on the next value in the next row.
Repeat steps 4-5 until you reach the last row.
Press Enter.
You can now select the results-cell (e.g. D1) and click and drag the small button to your lower right, across all the columns.
If you have a static reference - a constant in a cell that you do not wish to move use the $ operator, for example: $C$3 will not move column-wise or row-wise. $C3 can move column-wise but not row-wise and the opposite is true for C$3. This can be achieved in the Formula Bar, where you can also manually type in the function.

Resources