简体   繁体   English

用于提取特定细胞数据的公式逻辑

[英]Formula logic for extracting specific cell data

For extracting First £ figure and not the second one from sample data 用于从样本数据中提取First£figure而不是第二个

(24M UNLTD+INS 30GB £347+£30 S6) (24M UNLTD + INS 30GB£347 +£30 S6)

Following array formula has been used in Stackoverflow questions. 以下数组公式已在Stackoverflow问题中使用。

   {=MID(A1,FIND("£",A1),MIN(IF(ISERROR(MID(MID(A1,FIND("£",A1)+1,999),ROW($1:$999),1)+0),ROW($1:$999),999)))}

I attempted an analysis of the formula as represented in the image below. 我试图对公式进行分析,如下图所示。 I am not able to grasp the logic of part 我无法理解部分的逻辑

MIN(IF(ISERROR(MID(MID(A1,FIND("£",A1)+1,999),ROW($1:$999),1)+0),ROW($1:$999),999))

As to how it leads to a figure of 4. Request that this part of formula be elaborated to clarify the role of various constituents of this formula. 至于它如何导致4的数字。要求详细阐述这部分公式,以澄清该公式的各种成分的作用。

逐步研究配方

Try the following as a standard (non-array) formula, 尝试以下作为标准(非数组)公式,

=--REPLACE(REPLACE(A2, 1, FIND("£", A2), ""), FIND("+", REPLACE(A2, 1, FIND("£", A2), "")), LEN(A2), "")

First the inside REPLACE(A2, 1, FIND("£", A2), "") erases everything up to the first £ symbol, then the same logic is applied to erase everything in that modified text from the first + to the end. 第一内侧REPLACE(A2, 1, FIND("£", A2), "")会删除所有内容到第一£符号,那么相同的逻辑应用于从第一+擦除在于修改的文本一切到端。 The -- converts text-that-looks-like-a-number to an actual number. --将看起来像数字的文本转换为实际数字。

The array formula you provided uses a more convoluted logic. 您提供的数组公式使用更复杂的逻辑。

  1. FIND("£", A2) + 1 finds the starting point of the first number after the first £ symbol. FIND("£", A2) + 1在第一个£符号后面找到第一个数字的起始点。 eg The first £ is the 20 th character so it returns 21. 例如,第一个£是第20 字符,所以它返回21。
  2. MID(A2, FIND("£",A2)+1, 999) extracts the text following that first £ symbol. MID(A2, FIND("£",A2)+1, 999)提取第一个£符号后的文本。 The text might look like it starts with a number but it is text masquerading as a number. 文本可能看起来像是以数字开头,但它是伪装成数字的文本。 eg 347+£30 S6 例如347 +£30 S6
  3. In an array formula, ROW($1:$999) processes as a sequence of numbers from 1 to 999, incrementing by 1 for each cycle of calculation. 在数组公式中, ROW($1:$999)作为1到999的数字序列处理,每个计算周期递增1。
  4. MID(MID(A1, FIND("£", A1) + 1, 999), ROW($1:$999), 1) + 0) returns an array of text values, each one 1 character long and 1 position deeper into the text than the previous one. MID(MID(A1, FIND("£", A1) + 1, 999), ROW($1:$999), 1) + 0)返回一个文本值数组,每个文本值长1个字符,1个位置深入到文字比前一个。 eg 3 , 4 , 7 , + , £ , etc. 例如347+£
  5. +0 is used to try and convert each of these pieces of text to a number. +0用于尝试将这些文本中的每一个转换为数字。 The IFERROR function returns TRUE if a piece of text cannot be converted to a true number. 如果一段文本无法转换为真数,则IFERROR函数返回TRUE。 The first one that cannot be turned into a true number is the 4 th eg + 第一个不能变为真数的是第4 例如+
  6. The IF catches the TRUE on the fourth position and returns 4 from the second ROW($1:$999) . IF在第四个位置捕获TRUE并从第二个ROW($1:$999)返回4 ROW($1:$999) It has returned 999 for positions 1, 2 and 3. eg 999, 999, 999, 4, 5, etc. 它已经返回999位置1,2和3.例如999,999,999,4,5等。
  7. The MIN catches the smallest of these numbers returned as an array. MIN捕获这些作为数组返回的最小数字。 This is where the 4 comes from. 这就是4来自哪里。 eg 999, 999, 999, 4, 5, 999, ... 例如999, 999, 999, 4, 5, 999, ...

You can see this yourself by changing all of the 999's to 9 then using the Evaluate Formula command. 您可以通过将所有999更改为9然后使用“ 评估公式”命令来自行查看。 The reason changing to 9 is important is so that the returned arrays of number look like 1, 2, 3, 4, 5, 6, 7, 8, 9 which does not obfuscate the results quite a badly as 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 998, 999 . 更改为9的原因很重要,因为返回的数字数组看起来像1,2,3,4,5,6,7,8,9,它们不会将结果混淆得非常严重,如1,2,3, 4,5,6,7,8,9,10,11,12,13,14,...... 998,999

evaluate_formula
This shows the formula evaluated several steps into the process. 这表明该公式评估了该过程的几个步骤。 Note the 4 being returned to the MIN function . 注意4返回MIN函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM