简体   繁体   English

使用另一个单元格的子字符串填充 Excel 中的单元格

[英]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.

相关问题 Excel宏:检查当前单元格是否有子串作为另一个单元格 - Excel Macro: check whether the current cell has a substring as another cell 根据另一个单元格的内容在Excel中自动填充单元格 - Auto-populate Cell In Excel Based On Contents Of Another Cell Excel spreadsheed基于另一个单元格的值填充单元格 - Excel spreadsheed populate cell based on value of another cell Excel Function 在另一个单元格中找到任何给定的列值作为 substring - Excel Function to find any given column value as substring in another cell Excel在单元格中找到确切的子字符串 - Excel find exact substring in cell Excel-根据另一个单元格值填充多个单元格 - Excel - Populate multiple cells based on another cell value Excel:如何使用带有依赖于另一单元格的行的静态列自动使用数据填充单元格? - Excel: How to auto-populate cell with data using static column with a row dependent on another cell? Excel宏或函数:如果单元格不为空,则使用循环值(来自另一张纸)填充单元格区域(A列) - Excel Macro or Function: Populate a cell range (Column A) with a looped values (from another sheet) if cell is not blank 使用excel公式在单元格中查找确切的子字符串 - Find exact substring in cell using excel formula 如何查找单元格是否包含子字符串Excel - How to find if a cell contains a substring Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM