[英]Populate cell in Excel wtih substring of another cell
In Excel, I have a CSV in which column A is populated with category like strings, such as:在 Excel 中,我有一个 CSV,其中 A 列填充了诸如字符串之类的类别,例如:
ABCDE/FGHI/JKL/MNOPQR ABCDE/FGHI/JKL/MNOPQR
I need to auto populate column C with the value of the substring of everything after the last occurrence of the "/".我需要在最后一次出现“/”之后使用所有内容的子字符串的值自动填充列 C。 In this example, it would have to be populated with "MNOPQR"
在这个例子中,它必须用“MNOPQR”填充
Is there a function that could be used for this?有没有可以用于此的功能? "RIGHT" doesn't seem to do the trick.
“正确”似乎不起作用。 I don't know what the length of the substring will be in each row, so I definitely have to be able to look for the "/".
我不知道每一行中子字符串的长度是多少,所以我肯定必须能够找到“/”。
If your text is in A4, put this in another cell: 如果您的文字是A4,请将其放在另一个单元格中:
=MID(A4,LEN(LEFT(A4,FIND(CHAR(1),SUBSTITUTE(A4,"/",CHAR(1),LEN(A4)-LEN(SUBSTITUTE(A4,"/",""))))))+1,LEN(A4)-LEN(LEFT(A4,FIND(CHAR(1),SUBSTITUTE(A4,"/",CHAR(1),LEN(A4)-LEN(SUBSTITUTE(A4,"/",""))))))+1)
I think that should work. 我认为这应该有效。 Thanks to @Jerry for the main part, where it finds the last
/
in a string. 感谢@Jerry的主要部分,它找到了字符串中的最后一个
/
。
edit: Why downvote? 编辑:为什么downvote? It works for me:
这个对我有用:
edit 2: Per @ScottCraner, this is shorter: =MID(A1,SEARCH("}}}",SUBSTITUTE(A1,"/","}}}",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))+1,LEN(A1))
编辑2:每个@ScottCraner,这个更短:
=MID(A1,SEARCH("}}}",SUBSTITUTE(A1,"/","}}}",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))+1,LEN(A1))
Here's a bit shorter formula to return the last delimited substring in a string. 这是一个更短的公式,用于返回字符串中最后一个分隔的子字符串。
=TRIM(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",99)),99))
Replace the delimiter with 99 spaces, then return the rightmost 99 characters. 用99个空格替换分隔符,然后返回最右边的99个字符。 The leading characters must be spaces also, so TRIM gets rid of them.
前导字符也必须是空格,因此TRIM可以摆脱它们。
A simple formula approach using FilterXML
might be:使用
FilterXML
简单公式方法可能是:
=FILTERXML("<items><i>" & SUBSTITUTE(A1,"/","</i><i>") & "</i></items>","//i[position()=last()]")
Profitting from the dynamic features of vers.从 vers 的动态特征中获利。 2019+ you can change the cell address to a range input, eg A1:A10 allowing output in a so called spill range.
2019+ 您可以将单元格地址更改为范围输入,例如 A1:A10 允许在所谓的溢出范围内输出。
VBA approach VBA方法
As the VBA
tag has been recently added to OP, an obvious VBA approach would be to split the string input and get the last array element via Ubound()
:由于
VBA
标签最近被添加到 OP,一个明显的 VBA 方法是拆分字符串输入并通过Ubound()
获取最后一个数组元素:
Dim tmp As Variant
tmp = Split("ABCDE/FGHI/JKL/MNOPQR", "/")
Debug.print tmp(Ubound(tmp)) ' ~~> MNOPQR
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.