[英]Excel formula to populate Data based on a series or rules run on a different cell in the same worksheet
I need to populate a cell with some combination of data from another cell.我需要用来自另一个单元格的数据的某种组合来填充一个单元格。 Here's what my data looks like (sorry I can't post images):Column A = NameColumn B = TeamColumn C = Short Name
这是我的数据的样子(抱歉我不能发布图片):Column A = NameColumn B = TeamColumn C = Short Name
I'm trying to populate the Short Name based on a series of rules applied to the Name (column A).我正在尝试根据应用于名称(A 列)的一系列规则来填充简称。 I have some of it working.
我有一些工作。 So here's what I'm hoping to get to:
所以这就是我希望得到的:
this is the rule that's working: - If the name contains a ":" I'm populating the cell with the first 4 characters after that [IFERROR(B2&""&MID(A2, FIND(":", A2,1)+1,4),"")].这是有效的规则: - 如果名称包含“:”,我将在该单元格后填充前 4 个字符 [IFERROR(B2&""&MID(A2, FIND(":", A2,1)+ 1,4),"")]。 If it doesn't find the:, it's leaving Column C blank.
如果它没有找到:,它会将 C 列留空。 This was working perfectly until a new need was introduced...
在引入新需求之前,这一直运行良好......
So now Column C would be populated based on one of 3 things:所以现在 C 列将根据以下三件事之一进行填充:
Using my real data, at the end of the day Column C will display one of the following 3 things, displayed in the order of my rules above:使用我的真实数据,在一天结束时,C 列将显示以下 3 件事之一,按照我上面的规则顺序显示:
You can use the following formula to populate the C "Short Name" column:您可以使用以下公式填充 C“简称”列:
=IF(ISNUMBER(SEARCH(":", A2)), B2&" "&MID(A2,SEARCH(":", A2)+1, 4), IF(ISNUMBER(FIND("(ENH)", A2)), A2, ""))
This results in the following table:这导致下表:
NameColumn![]() |
TeamColumn![]() |
Short Name![]() |
---|---|---|
foobar:O&M ![]() |
Gold![]() |
Gold O&M![]() |
(ENH) UI Refactor ![]() |
whatever1![]() |
(ENH) UI Refactor ![]() |
Flubber![]() |
whatever2![]() |
Notes:笔记:
FIND()
is case-sensitive while SEARCH()
is not. FIND()
区分大小写,而SEARCH()
不区分大小写。 I used FIND()
for "(ENH)"
because it seemed as though you wanted an exact match.FIND()
用于"(ENH)"
,因为您似乎想要完全匹配。 If "(enh)"
should also match, use SEARCH()
."(enh)"
也应该匹配,请使用SEARCH()
。ISNUMBER(...)
can be used to check whether SEARCH()
and FIND()
returned a valid index instead of #VALUE!
ISNUMBER(...)
可用于检查SEARCH()
和FIND()
是否返回有效索引而不是#VALUE!
, and thus whether the search text was found. NOT(ISERROR(...))
could also be used. NOT(ISERROR(...))
也可以使用。Based on the little info given without posting samples this would work using Office 365: =IFERROR(B2&" "&LEFT(TEXTAFTER(A2,":",1),5),IF(LEFT(A2,5)="(ENH)",A2,""))
根据在没有发布示例的情况下给出的少量信息,这将使用 Office 365 工作:
=IFERROR(B2&" "&LEFT(TEXTAFTER(A2,":",1),5),IF(LEFT(A2,5)="(ENH)",A2,""))
TEXTAFTER checks for a (nth) delimiter and shows the text after that. TEXTAFTER 检查第 (n) 个定界符并显示其后的文本。 This is (if you ask me) easier to read than MID.
这(如果你问我)比 MID 更容易阅读。 But basically it does the same in this case.
但基本上在这种情况下它的作用是一样的。
If you need a better answer follow dbc's advice to post data as markdown table.如果您需要更好的答案,请按照 dbc 的建议将数据发布为降价表。
To accomplish this, you can use a combination of the IF, SEARCH, and LEFT functions in Excel.为此,您可以在 Excel 中组合使用 IF、SEARCH 和 LEFT 函数。 Here's an example formula that you can use in Column C:
以下是您可以在 C 列中使用的示例公式:
=IF(SEARCH(":", A2), MID(A2, FIND(":", A2,1)+1,4), IF(SEARCH("(ENH)", A2), LEFT(A2, 5), ""))
This formula first checks if there is a ":" in the value in Column A. If there is, it populates Column C with the characters after the ":".此公式首先检查 A 列的值中是否有“:”。如果有,它会用“:”后的字符填充 C 列。 If there isn't, it checks for "(ENH)" and populates Column C with the first 5 characters if it exists.
如果不存在,它会检查“(ENH)”并用前 5 个字符填充 C 列(如果存在)。 If neither of these conditions are met, it leaves Column C blank.
如果这两个条件都不满足,则 C 列留空。
I hope this helps.我希望这有帮助。 Let me know if you have any questions.
如果您有任何问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.