我有一个文件,其中数据包含一个单元格内的多个变量引用,该单元格中的变量(例如:XXXXX)包含在$符号(如$ XXXXX $)内。单元格值看起来像这样:
例如:
This is a requirement for $XXXXX$ where in data is fetched from $YYYYYY$ and needs to be placed under $ZZZZZ$
预期输出:
XXXXXX
YYYYYY
ZZZZZZ
我尝试了excel MID和FIND函数,但是可以使用VBA解决方案。
不适用
答案 0 :(得分:0)
如果您使用的是Excel 2016或更高版本或Office365,则可以使用TEXTJOIN function来执行此操作:
=TEXTJOIN(CHAR(10),TRUE,INDEX(TRIM(MID(SUBSTITUTE($D2,"$",REPT(" ",LEN(D2))),LEN($D2)*(ROW($1:$30)*2-1)+1,LEN($D2))),))
答案 1 :(得分:0)
例如,如果您的数据位于A10
中,则可以使用此(Excel 2013 +):
=IFERROR(SUBSTITUTE(INDEX(FILTERXML("<t><s>" & SUBSTITUTE($A$10," ","</s><s>")& "</s></t>","//s[starts-with(text(),'$')]"),ROWS($1:1)),"$",""),"")
并填写直到返回空白为止。
答案 2 :(得分:-1)
我可能看起来很复杂,但这解决了我的问题。现在,此公式可以在Excel中处理多达25个变量。
=IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",1)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",2))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",1))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",3)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",4))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",3))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",5)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",6))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",5))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",7)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",8))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",7))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",9)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",10))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",9))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",11)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",12))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",11))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",13)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",14))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",13))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",15)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",16))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",15))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",17)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",18))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",17))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",19)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",20))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",19))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",21)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",22))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",21))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",23)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",24))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",23))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",25)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",26))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",25))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",27)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",28))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",27))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",29)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",30))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",29))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",31)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",32))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",31))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",33)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",34))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",33))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",35)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",36))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",35))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",37)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",38))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",37))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",39)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",40))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",39))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",41)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",42))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",41))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",43)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",44))-FIND(">{{{",SUBSTITUTE($D2,"$","{{{",43))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",45)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",46))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",45))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",47)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",48))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",47))),"") &CHAR(10)&IFERROR(MID($D2,FIND("{{{",SUBSTITUTE($D2,"$","{{{",49)),1+FIND("}}}",SUBSTITUTE($D2,"$","}}}",50))-FIND("{{{",SUBSTITUTE($D2,"$","{{{",49))),"")