Excel Reverse Match - excel

I'm trying to find a way to do a reverse match in Excel. I have a column of TRUE/FALSE statements and I need to find a way to find both a match and a reverse match within this one column to find the difference between TRUE statements in both directions.
True
False
False
False
True
False
False
True
In this scenario from the perspective of the middle True statement the normal MATCH function going down would return a number of 4. I am trying to find an additional match function that would look upward to the TRUE statement and return a value of 5

Quick and dirty:
A1:A7: TRUE/FALSE
A8: Array formula: {=LARGE(IF(A1:A7=TRUE;ROW(A1:A7);"");1)}
The result will be the row number of the nearest TRUE from below.
The formula is inserted by Shift-Ctrl-Enter in a formula window. Curled brackets are inserted by Excel, not by a user.
If you need the shift from the last TRUE:
{=LARGE(IF(A1:A7=TRUE;ROW(A1:A7);"");2)}
Changing the last number in the formula moves you to the n-th TRUE from below.
Replacing LARGE with SMALL will give the row numbers from above. So it would possible to find the shift between relevant combinations by combining the formulae.

Related

2nd match, match multiple criteria, no VBA function/VBA code

Good Morning everyone.
I've got an array excel function which works based on 3 criteria as follows:
=IFERROR(INDEX('merged wz'!W:W,MATCH(1,('q log wz'!$C55='merged wz'!$M$1:$M$8000)*('q log wz'!$A55='merged wz'!$K$1:$K$8000)*(28='merged wz'!$P$1:$P$8000),0)),"No data")
now it works good for true and falses in the last part for one of the column datas where I need to return first match
(28='merged wz'!$P$1:$P$8000)
but this array will always have 2no trues and in other column I would like to modify this function so it replaces first true in array with false so it will return true only for the second match.
Any ideas how to do it? Thanks in advance.
Just showing one way of dealing with what you are trying:
Formula (CSE-entered) in D1:
=INDEX(C1:C8,SMALL(IF((A1:A8="a")*(B1:B8="x"),ROW(C1:C8),""),2))
This will return the 2nd match where column A=='a' and B=='x'.

Excel - Does Cell contain one of many specific 2 letter sequences

I work in a territory based position, and so I need to separate a list based on UK postcodes
I have a list of my own postcodes and need a formula to check each postcode against my list and give me a true or false value, I have tried 2 variations of 'cell contains one of many things' but I end up with false positives and I am not sure why. The second value should be False.
Many Thanks!
IFERROR(MATCH(D3,$B$3:$B$60,0)>0,FALSE)
MATCH()>0 will generate a TRUE if a match found, but generate an error if no match is found, so IFERROR() comes in handily to translate the error to FALSE.

Excel Formula: Count repetition factor in a list (Vlookup/Indirect help)

Apologies for the confusing title; I will explain my issue more clearly and detailed here.
So I have a list of booleans that includes a repetitive pattern, and I am trying to calculate the factor by which it repeats. The list will always begin with an unknown number of FALSE values before it begins the cycle and will always end with a TRUE followed by an unknown, but large number of FALSE values.
An example list:
FALSE
FALSE
TRUE
FALSE
FALSE
FALSE
TRUE
FALSE
FALSE
FALSE
TRUE
FALSE
FALSE
FALSE
FALSE
FALSE
FALSE
In this case, the factor of repetition I would like is 4 since the pattern repeats every 4 rows (excluding the beginning and end of the list).
I have tried a couple of methods of writing formulas to come up with 4 as the answer including uses of counts, some simple vlookups, and an offset attempt. So far, I have been unable to get a working formula. My guess is that the Indirect function may be of use here, but I haven't been able to wrap my head around the logic of using it yet.
In terms of a general strategy, I'm guessing that if I can find the indices of the rows of the first and second TRUE values, I can simply subtract them to find the repetition factor. (I can easily implement a row number or cell reference column into my spreadsheet if that would help at all too.)
Thanks in advance for any insight!
Try this formula:
=AGGREGATE(15,6,ROW($A$1:$A$17)/($A$1:$A$17),2)-MATCH(TRUE,$A$1:$A$17,0)
The MATCH finds the first row in which there is a TRUE.
The AGGREGATE is working like the SMALL(IF()) Function. when the cell is FALSE it will return a division by 0 error and the 6 in the function overlooks the errors. So the array in which the AGGREGATE is going to pull the second lowest row number is on those rows in which the cell is TRUE.
Edit
Here is a non array formula that does it also, based loosely on #GaryStudents answer:
=MATCH(TRUE,INDEX(A:A,MATCH(TRUE,A:A,0)+1):A1040000,0)
Get the "distance" between two consecutive occurrences of TRUE:
In C1 enter:
=MATCH("TRUE",A:A,0)
and in C2:
=MATCH("TRUE",INDIRECT("A" & C1+1 & ":A9999"),0)+C1
finally in C3:
=C2-C1

Use Two Different columns to compare to another worksheet

I have two columns that are different from each other. One containing numbers and the other containing text.
Trying to compare (match) both to another separate worksheet.
Of course, I can VLookup each one separatedly but that doesn't give me the answer I'm looking for.
I want to know if the first two columns correlate with the other worksheet.
I also tried an IF(VLookup but probably did it wrong.
To sum it up. If Column A and Column B are both on the other worksheet, then True or False.
Here's a worksheet function that'll do what you want assuming you're only looking in 1 column on worksheet 2. Just replace the values in [] with the actual ranges:
=NOT(OR(ISNA(MATCH([ColumnA],[OtherWorksheet],FALSE)), ISNA(MATCH([ColumnB],[OtherWorksheet],FALSE))))
Here's an example using actual ranges:
=NOT(OR(ISNA(MATCH(A1,Sheet2!A:A,FALSE)), ISNA(MATCH(B1,Sheet2!A:A,FALSE))))
FYI: You could also use this formula for conditional formatting if you don't want to display it in a cell.
Just to explain it:
MATCH will return a number if the value is found, otherwise it will be #N/A.
ISNA will indicate if the result was #N/A.
OR will result in TRUE if either nested ISNA indicates TRUE. (Meaning 1 value wasn't found)
NOT flips TRUE to FALSE and vice-versa.
End result, if both values are found returns TRUE otherwise displays FALSE.

Identify a subset of a range using TRUE statements

I am attempting to identify a subset of a range based on TRUE FALSE statements. An example is in the following chart below.
FALSE FALSE 1.21147
TRUE FALSE 1.20984
FALSE FALSE 1.21083
FALSE FALSE 1.210315
FALSE TRUE 1.21151
FALSE FALSE 1.21335
FALSE FALSE 1.213515
FALSE FALSE 1.212435
TRUE FALSE 1.212125
FALSE FALSE 1.21226
In this scenario I want a subset to be identified based on alternating TRUE statements. In the left side column the first TRUE statement would trigger the beginning of the subset an the TRUE statement in the second column would trigger the end of the subset. I then want to use a simple max function to identify the MAX in the third column. I would use an IF statement to determine whether or not the first TRUE statement is correct however, i am unable to figure out how to identify the subset of the range based on the TRUE statement in the second column. I also want to know whether or not this works from going from the top to the bottom if the statement could possible work going the bottom to the top. Any help would be most appreciated.
Part 1 can be done using a combination of MATCH, OFFSET and MAX
For this example I've assumed your data is located starting at cell A2.
For the sake of clarity I use some intermediate results in cells E1:E4. If you prefer a single formula, simply merge the intermediate formula into the final formula
Cell E2 = position of first TRUE in column A
=MATCH(TRUE,A2:A11,0)
Cell E3 = position of first TRUE in column B
=MATCH(TRUE,B2:B11,0)
Result formula, Max value in column C between the rows found in E2 and E3 (inclusive)
=MAX(OFFSET($C$1,E2,0,E3-E2+1,1))
Part 2 is more tricky: I don't think you can search up a range for a value. However, looking at your data it may be OK to search down for the second TRUE? If this is OK then:
Cell E4 = position of second TRUE in column A
=MATCH(TRUE,OFFSET(A2:A11,E2,0),0)
Or this, entered as an array formula (Insipred by Barry) which will get the last TRUE in the column
=MATCH(2, 1/(A2:A11=TRUE),1)
Result formula, Max value in column C between the rows found in E3 and E4 (inclusive)
=MAX(OFFSET($C$1,E3,0,E4+E2-E3+1,1))
your part about traversing the table from the bottom up confused me, and also don't know if you can have more than one subset, since you're penultimate row seems to be the opening of a new subset that is not closed. Anyway, hope that this helps. I'm assuming you don't want to use macros, in which case it would be trivial. What you can do is pad the top of the data set with an row that contains FALSE, FALSE, 0, 0, and add this formula to a fourth column starting with the first row of your set:
=IF(AND(NOT(A2),NOT(B2),OR(D1=0,AND(NOT(A1),B1))),0,C1)
That's assuming that your first row is row 2, and row 1 is used for the padding. A, B, and C are the three columns in your example, and D will print the value of the third column if it's within a subset, or zero if is not, so that you can easily calculate max() or whatever you want to do. I looks like this:

Resources