英文:
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]," _
& "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("A9").Formula2R1C1 = _
"=TOCOL(UNIQUE('1.Technical Compliance'!R[-2]C[4]:R[45]C[4]),1)"
- 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("A9").Formula2R1C1 = _
"=LET(data,'1.Technical Compliance'!R[-2]C[4]:R[45]C[4]," _
& "UNIQUE(FILTER(data,data<>"""")))"
- 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
""""
with0
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论