admin管理员组文章数量:1398814
I have the following set of data. In sheet A the data appears like "John D #23". In sheet B the data appears like "J Doe #23 (other info no numbers)".
I need to write an excel code for sheet B that finds "23" (or whatever number is in the cell). I need that number to be compared to Sheet1!A2:A, find the cell where "23" occurs and return all data left of "#" trimmed.
In a perfect world this is an arrayformula. Is this even possible?
I have the following set of data. In sheet A the data appears like "John D #23". In sheet B the data appears like "J Doe #23 (other info no numbers)".
I need to write an excel code for sheet B that finds "23" (or whatever number is in the cell). I need that number to be compared to Sheet1!A2:A, find the cell where "23" occurs and return all data left of "#" trimmed.
In a perfect world this is an arrayformula. Is this even possible?
Share Improve this question edited Mar 26 at 22:07 Friedrich 4,94313 gold badges56 silver badges51 bronze badges asked Mar 26 at 22:03 DaveDave 93 bronze badges 6 | Show 1 more comment2 Answers
Reset to default 1I am not sure I fully understood which piece of information you want to find but this is the solution that I have found for what I think you're after
=INDEX(TRIM(LEFT(Sheet1!A2:A, FIND("#",Sheet1!A2:A)-1)), MATCH(TRIM(MID(I9, FIND("#", I9), FIND(" ", I9,FIND("#", I9))-FIND("#", I9))), RIGHT(Sheet1!A2:A, LEN(Sheet1!A2:A)-FIND("#", Sheet1!A2:A)+1), 0))
You did not include the cell address for the sheet B array so I have just used the cell reference I9, but this will work as an array, simply substitute it for the array on sheet B
I am not sure exactly what you want, as you provided no pictures, but you should be abel to adapt what I have provided.:
Note:
- this requires 365
.
- I used LET
and broke it up a bit to make the algorithm more clear.
- lookup
range can be replaced by a table reference, or even a whole column reference if necessary, but the smaller the better.
=LET(
lookup, SheetA!$A$2:$A$1000,
a, REGEXEXTRACT(A2, "#\d+"),
b, XMATCH(TRUE, ISNUMBER(FIND(a, lookup))),
c, INDEX(lookup, b),
TRIM(LEFT(c, FIND(a, c) - 1))
)
Sheet A Data
Sheet B Data and Results
If Sheet1
is a table, then you would enter the lookup
formula in the first line of the table, and it will auto-populate the length of the table.
本文标签:
版权声明:本文标题:excel - Trying to extract a number from a string and compare it to another number in a set of strings - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744123630a2591854.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Sheet1!A2:A
is valid syntax only in Google sheets (as isArrayFormula()
) - you should adjust your tags accordingly. – Spectral Instance Commented Mar 26 at 23:18