简体   繁体   English

根据在同一工作表中不同单元格上运行的系列或规则填充数据的 Excel 公式

[英]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 列将根据以下三件事之一进行填充:

  1. Exactly what's happening now.正是现在正在发生的事情。 So if: exists populate column C based on the formula above所以如果:存在根据上面的公式填充C列
  2. If the: doesn't exist I need to inspect Column A for "(ENH)".如果:不存在,我需要检查 A 列中的“(ENH)”。 If (ENH) exists, I need column C populated with everything that's displayed in column A. If it exists, (ENH) will always be the first 5 characters displayed in column A.如果 (ENH) 存在,我需要用 A 列中显示的所有内容填充 C 列。如果它存在,(ENH) 将始终是 A 列中显示的前 5 个字符。
  3. If: or (ENH) doesn't exist, Column C stays blank如果:或 (ENH) 不存在,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 件事之一,按照我上面的规则顺序显示:

  1. Gold O&M黄金运维
  2. (ENH) UI Refactor (ENH) UI 重构
  3. BLANK空白的

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 foobar:运维 Gold金子 Gold O&M黄金运维
(ENH) UI Refactor (ENH) UI 重构 whatever1随便1 (ENH) UI Refactor (ENH) UI 重构
Flubber流氓 whatever2随便2

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.

相关问题 Excel 公式:如果单元格包含“...”,则根据首字母缩写规则将“...”插入相邻单元格 - Excel Formula: If cell contains “…”, then insert “…” into adjacent cell, based on acronym rules 根据工作表更改运行宏(单元格包含公式) - Run Macro Based On Worksheet Change (Cell Contains Formula) 检查不同工作表中的单元格是否为公式 - Checking If A Cell In A Different Worksheet Is A Formula 将Excel工作表保存到基于同一单元格的特定文件夹和文件名 - Save excel worksheet to specific folder and filename based on same cell Excel VBA如何根据不同工作表中单元格的值删除行 - Excel VBA How to delete rows based on the value of a cell in a different worksheet Excel 2013对不同单元格中的相同值和公式给出不同的答案 - Excel 2013 giving different answer for the same value and formula in different cell 自动将公式填充到Excel中的序列结尾 - Auto Populate Formula to end of series in excel 根据另一个工作表的单元格触发填充公式 - trigger filldown formula based on cell of another worksheet 当新数据加载到工作表中时,我将使用什么公式使列自动填充到 Excel 中? - What formula would I use to make a column automatically populate in excel when new data is loaded into a worksheet? 同一工作表中的不同单元保护 - Different cell protection in the same Worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM