列表中的唯一值

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

unique value from the list

问题

```
从上面的VBA代码的结果来看:

项目编号
2
4
5
6
7
0

如何避免在最后一行出现“0”值
```

英文:

Item no
2
4
2
7
5
6

Range("A9").Select
ActiveCell.Formula2R1C1 = _
"=UNIQUE('1.Technical Compliance'!R[-2]C[4]:R[45]C[4])"

The result from above VBA is:

Item no
2
4
5
6
7
0

From the result, how to avoid "0" value at last row

答案1

得分: 2

零与独特

使用TOCOL(很好!)

  • 如JvdV建议,使用 TOCOL 明显更优越(而且更高效)。
Range("A9").Formula2R1C1 = _
    "=TOCOL(UNIQUE('1.Technical Compliance'!R[-2]C[4]:R[45]C[4]),1)"
  • 它将忽略空单元格(它们伪装成包含零的单元格)。
  • 另外(第二个参数设置为3),使得公式在数据中存在错误值时不会失败。
  • 它不会忽略不为空的空白单元格。

使用LET和FILTER(糟糕!)

  • 如果要排除由空单元格产生的零,请使用以下公式:
Range("A9").Formula2R1C1 = _
    "=LET(data,'1.Technical Compliance'!R[-2]C[4]:R[45]C[4]," _
    &amp; "UNIQUE(FILTER(data,data<>"""")))"
  • 如果数据中存在错误值,它将失败。
  • 另外,它将忽略不为空的空白单元格。
  • 如果数据中有零,列表中将包含一个零。
  • 如果不想显示零,用 0 替换 """"
英文:

Zeros With UNIQUE

Using TOCOL (Great!)

  • As suggested by JvdV, using TOCOL is by far superior (and more efficient).
Range(&quot;A9&quot;).Formula2R1C1 = _
    &quot;=TOCOL(UNIQUE(&#39;1.Technical Compliance&#39;!R[-2]C[4]:R[45]C[4]),1)&quot;
  • It will ignore the empty cells (that are selling themselves as cells containing zeros).
  • It will additionally (with the 2nd parameter set to 3), enable the formula not to fail if there are error values in the data.
  • It will not ignore blank cells that are not empty.

Using LET and FILTER (Bad!)

  • If you want to exclude the zero produced by empty cells, use the following:
Range(&quot;A9&quot;).Formula2R1C1 = _
    &quot;=LET(data,&#39;1.Technical Compliance&#39;!R[-2]C[4]:R[45]C[4],&quot; _
    &amp; &quot;UNIQUE(FILTER(data,data&lt;&gt;&quot;&quot;&quot;&quot;)))&quot;
  • It will fail if there are error values in the data.
  • It will additionally ignore blank cells that are not empty.
  • If there are zeros in the data, a zero will be contained in the list.
  • If you don't want to show a zero at all, replace &quot;&quot;&quot;&quot; with 0.

huangapple
  • 本文由 发表于 2023年3月12日 14:04:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711333.html
匿名

发表评论

匿名网友

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

确定