Replacing value with ID if matching another value - excel

I have three columns:
A B C
1 TextOne TextOne 10
2 TextOne TextTwo 11
3 TextTwo
4 TextTwo
5 TextOne
6 TextTwo
Applying the formula below I was expecting the result 10:
=IF(ISNA(VLOOKUP(A1,$B$1:$C$2,2,FALSE)),"0",VLOOKUP(A1,$B$1:$C$2,2,FALSE))
but I am seeing NA and suspect this is connected with the format of the cells.
Where am I going wrong?

The issue was initially caused because I was trying to replace the value in cell applying the formula in the same cell.
As #datooo points in his comments:
Once the formula is entered the value you are looking up is gone

To ‘overwrite’ TextOne with 10 the simplest solution may be to filter ColumnA to select TextOne, enter 10 and copy down (change filter selection and repeat for TextTwo / 11 if required).
For a 'high volume' requirement (lots of replacements) use VLOOKUP (eg as in question) in a separate column and copy that column's results over the top of ColumnA with Paste Special Values.

Related

How to SELECT N values ABOVE and BELOW from specific value

If I have a table:
Column A
Column B
Column C
1
Jane
10
2
Stewe
9
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
10
Carol
1
I would like to SELECT 3 rows above and below WHERE Column B = someValue .
IF query SELECT * WHERE Column B = "Andrew" result should look like:
Column A
Column B
Column C
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
I know how to select one row, but cant understand how to select such range.
Thanks for ideas!
You can limit and offset inside your QUERY():
=QUERY(A1:C,"limit "&2+MIN(5,MATCH(D1,B:B,0))&" offset "&MAX(0,MATCH(D1,B:B,0)-5))
Well, this was fun...
If 3 above or below are not available then blank... rolling data around is a different proposition.
Below the image is the list of formulae used.
So, per cell not including the data validation that is based on cells B2:B11
A14 and dragged down:
=IFERROR(INDEX($A$2:$A$11,MATCH(B14,$B$2:$B$11,0)),"")
C14 and dragged down:
=IFERROR(INDEX($C$2:$C$11,MATCH(B14,$B$2:$B$11,0)),"")
Cells B14 through B20:
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=3,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-3)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=2,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-2)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=1,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-1)),"")
=E2
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+1),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+2),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+3),"")
In Excel 365, you could try:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
In Google sheets, on the other hand, the formula would be:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
(spot the difference).
Excel
Google Sheets
This should produce what you want in all cases:
=IFERROR(FILTER(A2:C,B2:B<>"",ROW(A2:A)>=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)-3,ROW(A2:A)<=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)+3))
Of course, you can replace the two instances of "Andrew" with a cell reference (one where you type a changeable name).
This just looks up the row in a curly-bracket array formed from the names and row numbers and uses FILTER to keep results to rows between +/-3 rows of where the target name is found. If you choose the first name (or any other name), you won't get an error; because even if the target name were on Row 1 and the formula goes looking for anything "greater than or equal to 1 minus 3, all rows will be greater than a negative number. Same on the high end. You just won't get a full seven names if there aren't at least three other rows prior to or after the target row.
this not the best solution but it will work , you can use a helper column 'D' that contains the following formula =if(countif(INDIRECT("B"&ROW()+3&":"&"B"&ROW()-3),"Andrew")>0,TRUE,FASLE)
and u can query from here like this SELECT * WHERE Column D = TRUE

Excel mapping and create a new column

Excel file columns:
A B C
2 two 3
5 five 8
3 three 10
8 eight 11
12 one 15
I want to create a new column Din same file like below:
A B C D
2 two 3 three
5 five 8 eight
3 three 10
8 eight 11
12 one 15
I want to map C and A and if there's a match D takes values of B.
Example: Value 3 in C is present in A, so D will take corresponding B value three.
Thanks!
So building on BigBen's additional suggestion of using an IFERROR, I believe you want something akin to this in Column D:
=IFERROR(VLOOKUP(C1, A:B, 2, FALSE), "")
... and then drag down the formula throughout Column D
Now, there are some assumptions being made here:
Your data does not have any header row, ala the data starts in Row 1, not Row 2
You want empty/blank values where there is no exact match (this is BigBen's IFERROR suggestion). Your current question layout seems to suggest this. Otherwise, you'll get #N/A in all those blank cells in Column D.
EDIT: To confirm, I used your data (though I started in Row 2), and here's how it looked after -
If one has DA-functionality you could use:
1) - Excluding empty cells using FILTER:
Formula in D1:
=FILTER(B1:B5,COUNTIF(C1:C5,A1:A5)>0)
2) - Including empty cells using XLOOKUP:
Formula in D1:
=XLOOKUP(C1:C5,A1:A5,B1:B5,"")
If one does not have access to DA-functionality you could use:
1) - Excluding empty cells using INDEX, MATCH and SMALL:
=IFERROR(INDEX(B$1:B$5,SMALL(IFNA(MATCH(C$1:C$5,A$1:A$5,0),""),ROW(A1))),"")
Note 1 - This needs to be array entered through CtrlShiftEnter
Note 2 - Alternatively, one could use a non-array entered approach including AGGREGATE as per #basic: =IFERROR(INDEX(B$1:B$5,AGGREGATE(15,6,MATCH(C$1:C$5,A$1:A$5,0),ROW(A1))),"")
2) - Including empty cells using VLOOKUP:
Please refer to the other answer given by #Gravity here.
Basically the difference between both approaches could be vizualised like:

How to create two columns that match all values from a third in excel or OpenOffice?

I have one column with 10 cells, every cell have a different value in it. How can I create two columns that have every cell matching with the other 9.
Example :
1
2
3
4
5
6
7
8
9
10
Become
1 2
1 3
1 4
1 5
......
2 1
2 3
2 4
2 5
.....
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
I am not sure I read the same question as others did. I think your example was merely that, an example, and that these first 10 cells could contain anything and you wanted every permutation that could result. While I think that the other answers might work for the specific situation you describe, they may not work if you had other data in those cells. Hence I am offering a variation which uses a similar technique to reference the cells indirectly. The permutations of 2 objects from a set of 10 unique objects would result in 90 objects (which is why the above technique from Tom Sharpe references 90).
Assuming that you have your 10 items in A1 through A10, I would put the following formula in B1 and copy it down through B90:
=INDIRECT("R"&QUOTIENT(ROW()-1,9)+1&"C1",FALSE)
Also, I would use this formula in C1 and copy it down through C90:
=INDIRECT("R"&MOD(ROW()-1,9)+1+((MOD(ROW()-1,9)+1)>=QUOTIENT(ROW()-1,9)+1)&"C1",FALSE)
The result should give you something like what is shown in the attached matching your example.
Likewise, it would show the permutations of any values you had in A1 through A10 as shown in the second attached picture with words instead of the numbers 1 through 10.
In Excel (without VBA or such like), one way:
In A1 and copied down to A100: =INT((ROW()+9)/10).
In B1 and copied down with Ctr to B10: 1.
Select B1:B10 and copy down with Ctrl to B100.
In C1 and copied down to C100: =A1=B1.
Select ColumnsA:B, Copy, Paste Special, Values.
Filter A:C ,select TRUE in ColumnC and delete all blue indexed (visible content) rows.
Delete ColumnC.
Or in A1:
=QUOTIENT(ROW()-1,9)+1
copied down to A90 just to be different.
Then in B1:
=MOD(ROW()-1,9)+1+((MOD(ROW()-1,9)+1)>=A1)
copied down to B90.

Conditional formatting in Excel based on formatted output in other table

Say,I have 2 tables...Tables are related...
1 3 5 7
8 8 9 10
11 12 13 14
&
2 3 5 5
1 1 1 1
3 4 4 4
I have highlighted top 5 values in first table using conditional formatting rules.Now I want to highlight cells in the second table based on first table...Assume 11 12 13 14 7 10 are highlighted in first table....I want to highlight cells in second table occupied same position as of in highlighted cells in first table..i.e. 3 4 4 4 5 1 should be highlighted...How can I do that
Use Excel functions RANK and/or COUNTIF to calculate a sequential ranking list column for the first table. The expression is explained here.
For the second table, you can then use conditional formatting based on the computed rank.
Might just be an elaboration of #Axel's answer and I agree the details of the question do not make sense but the position of a selection of top (or bottom) ranked cells in one array (say A1:D3) can be used to determine whether or not to format a cell in the corresponding position of another array (say H5:K7):
Select from H5 to K7, then HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::
=RANK(A1,$A$1:$D$3,)<6
Format..., select formatting, OK, OK.
Change the 6 to suit how many cells are to be formatted which for <6 could be more than five if the value ranked fifth is duplicated.

Excel - find a value in two dimensions

I have a table of data like this:
a b c d
1 1 2 3 4
2 5 6 7 8
3 9 10 11 12
4 13 14 15 16
And I want a formula that finds the maximum value (16) and return its row number (4 in this case). How do I do that?
INDEX(a1:d1,MATCH(MAX(a1:h4),a1:h4,0),) ain't working :(
Sheet layout:
B1:E1: column headers
A2: A5: row headers
B2:E5: data
Array formula:
{MAX(IF(B2:E5=MAX(B2:E5);ROW(B2:E5)-1;""}
As the question asked for "d" as a result initially, the corresponding array formula is below:
{=OFFSET(A1;MAX(IF(B2:E5=MAX(B2:E5);ROW(B2:E5)-1;""));0)}
Shift-Ctrl-Enter to in a formula window to insert. Curled brackets are inserted by Excel,not by a user.
And one more humble girl's opinion:
=ADDRESS(ROW(OFFSET(A1,MAX(IF(B2:E5=MAX(B2:E5),ROW(B2:E5)-1,"")),0)),COLUMN(OFFSET(A1,0,MAX(IF(B2:E5=MAX(B2:E5),COLUMN(B2:E5)-1,"")))),4) - but entered as ARRAY formula via Ctrl+Shift+Enter, will return E5 (assuming #Jüri Ruut regions), which is simply the address of the desired cell.
Hope this attached screenshot is self explanatory?
Ok, I would program a macro like that:
Iterate over each row - find the maximum for that row.
Store the value in a array and than compute the maximum again.
Probably it would work with formulas too. Simply compute the maximum of each row in a seperate column and THEN compute the maximum of that column.
Try this array formula
=MIN(IF(A1:H4=MAX(A1:H4),ROW(A1:H4)))
confirmed with CTRL+SHIFT+ENTER
if there are multiple occurrences of the MAX value in A1:H4 then the formula will give you the first row in which it occurs

Resources