Index only cells in a column from another sheet if another cell in same row has a value greater than 0 - excel

So I have an example below of what I'm wanting to do.
Basically I need to Index Column B from Sheet 1 into Sheet 2 BUT ONLY if the values in Column W in Sheet 1 are greater than 0. If it's not then I don't want it to be included in. The only column to Index is B starting from row 5 to say 100. Same for Column W.
I was trying to do it myself as I found This which is very similar as what I'm wanting to do but I couldn't figure it out.
Sheet 1
Row# Column B | Column(s)… | Column W
=================================
5) Thing 1 | | 0
6) Thing 2 | | 3
7) Thing 3 | | 0
8) Thing 4 | | 1
Sheet 2
Row# Column B | Column C | Column D
=================================
5) Thing 2 | 3 |
6) Thing 4 | 1 |
7) | |
8) | |

EDIT #3
You can use either SMALL, LARGE function to return the values from Column B on your Sheet1.
Presume you have given the following names:
Sheet1ColB: Sheet1!B5:B100
Sheet1ColW: Sheet1!W5:W100
Here is the formula to be put in Cell B5 on your Sheet2. Please note it is an array formula so you need to press Ctrl+Shift+Enter to confirm.
{=IFERROR(INDEX(Sheet1ColB,SMALL(IF((Sheet1ColW>0)*(LEN(Sheet1ColW)>0),ROW(Sheet1ColW)),ROW()-4)-4),"")}
or
{=IFERROR(INDEX(Sheet1ColB,LARGE(IF((Sheet1ColW>0)*(LEN(Sheet1ColW)>0),ROW(Sheet1ColW)),ROW()-4)-4),"")}
You can then use INDEX+MATCH to return the value from Column W on your Sheet1 in Column C on your Sheet2:
=IFERROR(INDEX(Sheet1ColW,MATCH(B5,Sheet1ColB,0)),"")
In the above screen-shot Solution 2 is using AGGREGATE which follows the same logic as SMALL/LARGE.
As you can see the sample data has taken into account duplicated values in Sheet 1 Col W, blank cells in both Column W and Column B on Sheet1, and blank cells, negative value or 0 value in Column B only on Sheet1.
Cheers :)

Use AGGREGATE() formula to filter based on condition.
=IFERROR(INDEX($A$5:$A$8,AGGREGATE(15,6,(ROW($A$5:$A$8)-ROW($A$4))/($B$5:$B$8>0),ROW(1:1))),"")

Related

Match corresponding records on different sheets

For example: I have two sheets, both with matching columns, Column A and B are the same on both sheet. Column A on both sheets will always match, they will always contain the same value, but Column B may be different, like in the example bellow. All of the data matches besides row 3. In Sheet 1 it has "c" in column B, but in Sheet 2 it has "f" in column B.
What I am trying to do is have a column that shows if they match or not, so in the example, row 1, 2 and 4 would all have "match", but row 3 it would say "mismatch" and I am trying to have this all on a separate sheet (sheet 3).
I think Vlookup would be the best bet, but I have no idea where to start. Any help would be appreciated.
Sheet 1:
ColumnA | ColumnB
1 | a
2 | b
3 | c
4 | d
Sheet 2:
ColumnA |ColumnB
1 | a
2 | b
3 | f
4 | d
Sheet 3:
ColumnA |ColumnB
1 | match
2 | match
3 | mismatch
4 | match
If two lookup equal each other than match, otherwise no match, In B1 of Sheet3:
=IF(VLOOKUP(A1,Sheet1!A:B,2,FALSE)=VLOOKUP(A1,Sheet2!A:B,2,FALSE),"Match","Mismatch")
And copy down.

Excel function for comparing columns with repeated values

I'm using excel and have two columns (A & B) with values
I want to search for each value in Column A and return the position in Column B.
I'm using this formula:
IFERROR(MATCH("Values in Column A";"Array = Column B";0);0)
The results are:
Column A | Column B | Column C
1 | 4 | 2
2 | 1 | 3
3 | 2 | 4
4 | 1 | 1
1 | 2 | 2
| 3 |
It works fine if it doesn't encounter repeated values. However, I want it to encounter repeated values, so the formula should ignore the ones it was encountered before and go through the others. So the correct result should look like this:
Column C
2
3
5
1
4
Can you help me on this? Is there a VBA routine for this?
From the article Getting the 2nd matching value from a list using VLOOKUP formula, you can create a helper column to affix the instance number of each value, to create unique id's.
For example, in Column C, add the following function:
=A1&"-"&COUNTIF($A$1:A1,A1)
Note: The relative reference on the count range will cause the applicable range to grow as it is dragged down. The count of the items matching that cell in a range containing only that cell should always be one. As it gets dragged down to include other cells, it will increment accordingly.
Then add the same thing in Column D to get the instances of cells in Column B:
=B1&"-"&COUNTIF($B$1:B1,B1)
Finally, do the math you want to do in Column E like this:
=IFERROR(MATCH(C1,D:D,0),0)

Google spreadsheet relative row numbering + skip empty cell

Using Google spreadsheet, I need a column to show relative row numbering, so that:
Spreadsheet rows can be moved around, and numbering stays relative (meaning that if I move row number 12 between rows 4 and 5, this row becomes number 5, previous 5 becomes 6, etc.)
Using a condition based upon a cell value in a given row, the row numbering cell may be empty (or not); if empty, that row number is being skipped, and numbering takes back up in the next row where the condition is unmatched.
Here is an example:
| Row nbr | B col. | [Explanation] |
|---------|:-------:|-------------------------------------|
| R01 | Value 1 | |
| R02 | Value 1 | |
| R03 | Value 2 | |
| | Value 3 | Col. B value = 3 => Col. A is empty |
| R04 | Value 2 | Numbering takes up |
| R05 | Value 1 | |
| | Value 3 | Col. B value = 3 => Col. A is empty |
| R06 | Value 2 | Numbering takes up |
| ETC. | | |
Here, the condition (to skip numbering) would be "IF corresponding B cell = Value 3" (then skip numbering)
Right now, I'm using a formula that matches requirement #1 above:
=ROW(INDIRECT("A"&ROW()&":A"))-9
(The trailing "-9" is just an offset so numbering can start at 01 from row 10).
So basically, I need to adapt (or change) this code so that besides relative numbering, for row N, if corresponding B column cell value = XYZ, then A column cell is empty (vs. numbered): that row is being skipped, and numbering takes back up from N on the next row where the B cell value ≠ XYZ.
Here's a Google spreadsheet example.
Many TIA's.
I strongly recommend not to use ROW() with explicitly specified offset in formula because should you delete/add rows above your table, your will have to adjust formulas in all cells. Here's my solution (column A:A is row numbers, B:B - values, start adding formula in cell A10):
=IF($B10="Value 3","",ROWS($B$10:$B10)-COUNTIF($B$10:$B10,"Value 3"))
Or if you insist on relative rows (change 10 to your offset from top):
=IF(INDIRECT("B"&ROW())="Value 3","",ROWS(INDIRECT("B"&10&":B"&ROW()))-COUNTIF(INDIRECT("B"&10&":B"&ROW()),"Value 3"))

In Excel, add 1 if not number, or else add the number

In excel, how do I write a formula that does the following:
In a certain cell range, if the cell contains a non-numeric entry, add one, or else add the number the cell contains.
for example
4
xyz
def
bc
2
0
=9
or
1
ab
cd
2
af
=6
Contents of the data A1:A6
4
xyz
x
2
y
0
Write the following formula in cell B1
=SUM(A1:A6)+(COUNTA(A1:A6)-COUNT(A1:A6))
I would use an array function:
{=SUM(IF(ISNUMBER(A1:F1);A1:F1;1))}
Enter by writing "=SUM(IF(ISNUMBER(A1:F1);A1:F1;1))" and pressing Ctrl+Shift+Enter.
A | B | C | D | E | F | G
--+---+---+---+---+---+---+---
1 | 4 | a | b | c | 2 | 0 | {=SUM(IF(ISNUMBER(A1:F1);A1:F1;1))}
What I would do is write a the formula
=ISERROR(Cell+0, 1)
next to each cell, and then sum across these cells.
What the formula does is it returns the value of the cell if the cell is a number, and it returns the number 1 if the operation "cell + 0" errors out (e.g. when the cell's value is not a number).
See the picture below for how i applied this to your first example.

Find two matching rows and display data from the thirt one (Excel)

So i have Two Sheets.
First sheet contains two columns
BRAND | LEFTOVER
The second sheet consists of two columns also.
BRAND | LEFTOVER (%)
So in case if the BRAND row value in the first Sheet will match the BRAND row value in the second i want to display the matching LEFTOVER (%) row value in the first sheet rows in the column LEFTOVER.
Kind of lost here.
Appreciate any ideas. Thanks.
In Sheet2:
. A | B
--------------------
1 BRAND | LEFTOVER %
2 X | Y
3 |
In Sheet1:
. A | B
--------------------
1 BRAND | LEFTOVER
2 X | =VLOOKUP(A2,Sheet2!A:B,2)
3 |
The VLookup function searches for its first parameter (in this case the value of Sheet1!A2) in the first column of the range denoted by the second parameter (in this case the leftmost column of the range containing columns A and B on Sheet2)
It then returns the value from that same row of the range that is to the right in the columns denoted by the third parameter (1 is the leftmost column where the matched value was). So in this case we use the number 2 because 1 means column A and 2 is column B (which explains why we used a two column wide range for the second parameter - it needed to encompass the column the result was in)
This isn't the only way to do this, but it is the easiest.
As Jerry stated VLOOKUP is the simplest way to do this.
HOWEVER if you have multiple/repeat instances (rows) in BRAND, VLOOKUP will only return the first record (row) that appears in your data.
If this is the case, you will need to add either a unique identifier column; and/or additional criteria to differentiate between the repeat instances.
As an example column A is used as a unique identifier to differentiate between the 2 'Nike' rows.
A B C
1 BRAND LEFTOVER
2 Nike 50
3 Adidas 25
4 Reebok 30
5 Nike 29
I feel that you can use vlookup to accomplish your goals.
Let me explain it in a bit detail.Suppose you have two sheets as:
A | B | A | B
--------------------- | -------------------
1 BRAND | LEFTOVER % | 1 BRAND | LEFTOVER
2 X | Y | 2 X | =Vlookup(A2,Sheet2!A:B,False)
3 | | 3 |
Sheet2 | Sheet1
After this you can drag this formula for the entire range. This will automatically make the formula correct for the below cells as well.
Also, if you need to populate any other fields from the Sheet2 then you can also use the vlookup as an array formula like: VLOOKUP(A2,Sheet2!A:B,{1,2,3,4},FALSE)
Enter this as an array formula using Crtl+Shift+Enter
Here {1,2,3,4} stands for the columns to be fetched.
If you want to know more about vlookup then read this article: http://www.exceltrick.com/formulas_macros/vlookup-in-excel

Resources