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

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.

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

Identify row or column addition or deletion in excel

I'm looking for a solution which can able to identify the any row or column addition or deletion in a excel file.
What I have thought of as of now by using the LCS i.e. "Longest common sub-sequence" algorithm I can find out the common sub-sequence between two versions of a excel file, but this method is not 100% correct.
For e.g.
Excel version 1
1 2 4 5 9 3
4 9 3 7 5 3
8 2 7 9 3 8
9 7 2 8 2 4
After update, I remove 1 row (2nd row) and added 1 row (at same place i.e. 2nd).
Excel Version 2
1 2 4 5 9 3
4 9 5 7 5 3
8 2 7 9 3 8
9 7 2 8 2 4
Added row is almost similar except 1 cell item. In this case LCS would not work as it most of the cell items would be similar and I can't able to identify row was removed first and a new row was added.
Here is a proposed "comparison" algo :
label each lines (row), in the original file + new file
(a) find equivalent lines & match them (b) mark it.
(a) find new lines (b) mark it.
Example execution :
Assuming both data is located in A1:F4 in each file. In both file add new columns that do [1].
In Sheet1 & Sheet2 :
in H1 put =ROW()
in I1 put =A1&","&B1&","&C1&","&D1&","&E1&","&F1
in J1 put =H1&" - "&I1
drag all downwards.
So for [2] Use a third excel file (or new sheet), compare the "content" and the "content-rowNumber" column. Since I'm using Sheet1 as Original file & Sheet2 as the NewFile, my formulas is as per below.
In Sheet3 :
in B1 label "row number"
in C1 label "content InOriginal"
in D1 label "RomNum&content InOriginal"
in E1 label "content NewFile"
in F1 label "RomNum&content NewFile"
in H1 label "content match"
in I1 label "content & rowNumber match"
Then,
in B2 put "=Sheet1!H1"
in C2 put "=Sheet1!I1"
in D2 put "=Sheet1!J1"
in E2 put "=Sheet2!I1"
in F2 put "=Sheet2!J1"
in H2 put "=EXACT(C2,E2)"
in I2 put "=EXACT(D2,F2)"
and drag downwards.
the TRUE/FALSE result is the result of the (basic) comparison. Should you need to do more analysis, you may proceed to modify/add the needed formulas.
Hope it helps. ( :
The sample file is here.

A function that will lookup a reference

Before I get started thanks for taking your time and helping.
This is what my worksheet looks like:
Row # B C D E F
2 1 Product 1 B2 B3 B4
3 2
4 6
5 1 Product 2 B5 B6
6 5
7 4 Product 3 B7
I was trying to follow this formula: (The best answer one or green check mark) return values from multiple matching rows
I got all the way to the =IFERROR(INDIRECT(lookups!H5),"") but can not get this to work.
What I am tying to do is order the numbers in Column B to go to the right of the product. Which I was able to get the column it is in (B) and the row number it is in (B2). I would like to change the value (B2) to the number that is there.
I would like it to look like this:
Row # C D E F
2 Product 1 1 2 6
3
4
5 Product 2 1 5
6
7 Product 3 4
If someone could help explain this to me or find a better way that would be great.
Not sure what is to happen to columnB but if you replace B with "="B throughout columns D:F then select each of these in turn and apply Text to Columns with Tab as the delimiter the 'cell references' convert to formulae referring to the values in B. If you want to delete columnB copy D:F and Paste Special, Values over the top.

Way to count last values before each zero?

I am trying to count the last value before it resets back to zero multiple times per column. Here is my example
1
2
3
4
5
6
7
8
0
1
2
3
4
5
6
0
1
0
0
1
2
3
0
And the list goes on but for this example I would be looking to do something like a LARGE or SMALL where I could get the answers like this:
8
6
1
3
Ultimately I would like them to be in the descending order, but if that isn't part of the formula I can take care of that if I can just figure out a way to capture them.
Can this be done?
You can try the following in column B try the following =IF(A2=0,IF(A1=0,"";A1),"")
then filter column B on non blank value
Put your original data in column B
In cell A2 enter:
=IF(AND(B2<>0, B3=0),MAX($A$1:A1)+1,"")
and copy down. Finally in C1 enter:
=VLOOKUP(ROW(),$A$1:$B$23,2,FALSE)
and copy down till you see errors. Should look like:
Basically column A is a "helper" column used to mark all the "good" values to facilitate easy pick-up

Replacing value with ID if matching another value

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.

Resources