问题
I have the following
how can i get the sum number from T1 example or A1?
The Variable in Column A can be variant.
Result in C2 should count how many T1 in Column A or how many A1 in Column A and so on for other Values.
回答1:
Try following array formula:
=SUM(IFERROR(SEARCH(C1,RIGHT($A$1:$A$12,LEN(C1)))*((SUBSTITUTE($A$1:$A$12,C1,""))),0))+COUNTIF($A$1:$A$12,C1)
Array formula after editing is confirmed by pressing ctrl
+ shift
+ enter
回答2:
As a follow-up on this older question I believe you could try the following:
Formula in C2
:
=SUM((ISNUMBER(SEARCH("*"&B2,A$1:A$12)))*(IFERROR(LEFT(A$1:A$12,SEARCH(B2,A$1:A$12)-1)*1,1)))
Beware that this answer is applicable to the sample data provided but will fail when you start having data as T11
etc. However, you haven't provided any further information so hopefully this will do.
A much more solid solution could be to use some XPATH
:
=SUM(IFERROR(SUBSTITUTE(FILTERXML("<t><s>"&TEXTJOIN("</s><s>",1,A$1:A$12)&"</s></t>","//s[substring(., string-length(.)-"&LEN(B2)-1&")='"&B2&"']"),B2,"")*1,1))
Note: Confirm both options through CtrlShiftEnter
回答3:
You can try below formula and see if it helps.
=SUMPRODUCT(IF(RIGHT($A$1:$A$12,LEN(B2))=B2,LEFT("0"&$A$1:$A$12,LEN($A$1:$A$12)+1-LEN(B2))+($A$1:$A$12=B2),0))
Copy down as much needed.
来源:https://stackoverflow.com/questions/61655039/excel-formula-to-find-a-specific-number-in-variant-variable