How do I write a formula in excel that lists a value contained in one cell for each incremental number value contained in another cell?

huangapple go评论63阅读模式
英文:

How do I write a formula in excel that lists a value contained in one cell for each incremental number value contained in another cell?

问题

我有一个包含CSV数据的单元格(单元格A)。我有另一个包含数量值的单元格(单元格B)。我想要一个公式,列出单元格B中包含的每个递增值所对应的单元格A。

我已尝试搜索相关主题,但没有类似的结果。

我想要它运行的示例:

单元格A是数据单元格
B是5,
列C:C(公式)是数据,
溢出到C:C中的下一行是数据,
溢出到C:C中的下一行是数据,
溢出到C:C中的下一行是数据,
溢出到C:C中的下一行是数据
英文:

I have a cell that contains csv data (Cell A). I have another cell that contains a quantity value (Cell B). I would like a formula that lists the Cell A for each incremental value contained in Cell B.

I have tried searching for related topics with no similar results.

An example of how I would like it to function:

Cell A is DataCell 
B is 5,
Column C:C (Formula) is Data,
spill into next row in C:C is Data,
spill into next row in C:C is Data,
spill into next row in C:C is Data,
spill into next row in C:C is Data

答案1

得分: 1

根据您的评论,我认为我理解您的需求。您希望在单独的单元格中重复某个值n次。这里CSV值的事实与此无关。

在C1中的公式:

=INDEX(A1,SEQUENCE(B1,,,0))

或者更好的方式:

=EXPAND(A1,5,,A1)
英文:

Based on your comments, I think I understand what it is you are after. You wish to repeat a certain value n-times in seperate cells. The fact that it's a CSV-value is irrelevant here.

How do I write a formula in excel that lists a value contained in one cell for each incremental number value contained in another cell?

Formula in C1:

=INDEX(A1,SEQUENCE(B1,,,0))

Or better:

=EXPAND(A1,5,,A1)

答案2

得分: 0

如果您只想在同一行内由换行符分隔,那么对于C2单元格,公式将如下所示:

=IF(
  OR(
    A2 = "",
    B2 = "",
    B2 < 1
  ),
  "",
  A2 & IF(
    B2 < 2,
    "",
    REPT(
      CHAR(10) & A2,
      B2 - 1
    )
  )
)

如果您希望C2单元格自动换行,您可以像@JrdV建议的那样将其转换为数组,使用TEXTSPLIT函数,将第二个参数留空,并使用第三个参数来分隔行。所以...

=IF(
  OR(
    A2 = "",
    B2 = "",
    B2 < 1
  ),
  "",
  TEXTSPLIT(
    A2 & IF(
      B2 < 2,
      "",
      REPT(
        CHAR(10) & A2,
        B2 - 1
      )
    ),
    "",
    CHAR(10)
  )
)

这假设A2中不包含任何换行符。如果包含换行符,则需要使用CHAR(10)以外的分隔符,例如"&#231;"或"&#167;"。

英文:

If you just want it separated by newline character in the same row, then for C2 the formula would be

=IF(
  OR(
    A2 = &quot;&quot;,
    B2 = &quot;&quot;,
    B2 &lt; 1
  ),
  &quot;&quot;,
  A2 &amp; IF(
    B2 &lt; 2,
    &quot;&quot;,
    REPT(
      CHAR(10) &amp; A2,
      B2 - 1
    )
  )
)

If instead you want C2 to spill down, you can convert it into an array using TEXTSPLIT like @JrdV suggested, with an empty 2nd argument and using the 3rd argument to split into rows. So...

=IF(
  OR(
    A2 = &quot;&quot;,
    B2 = &quot;&quot;,
    B2 &lt; 1
  ),
  &quot;&quot;,
  TEXTSPLIT(
    A2 &amp; IF(
      B2 &lt; 2,
      &quot;&quot;,
      REPT(
        CHAR(10) &amp; A2,
        B2 - 1
      )
    ),
    ,
    CHAR(10)
  )
)

This assumes A2 doesn't contain any newline characters. If it does then you would have to use a delimiter other than CHAR(10), Perhaps "ç" or "§".

huangapple
  • 本文由 发表于 2023年6月8日 02:25:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定