在一列中查找唯一值并使用 VBA 代码将它们连接到一个单元格中(删除开头和结尾的空白以避免重复)
我正在测试此功能以找到列的唯一值并将其显示在逗号分隔的单元格中。通过以下功能,它可以执行我想要的,但是当开头或结尾处有空白时,它会返回由这些空白引起的重复值。
这是功能:
Function ConcatUniq(xRg As Range, xChar As String) As String
'updateby Extendoffice
Dim xCell As Range
Dim xDic As Object
Set xDic = CreateObject("Scripting.Dictionary")
For Each xCell In xRg
xDic(xCell.Value) = Empty
Next
ConcatUniq = Join$(xDic.Keys, xChar)
Set xDic = Nothing
End Function
非常感谢!
I am testing this function to find unique values of a column and display them in a cell separated by commas. With the following function it does what I want, but when there are blanks at the beginning or at the end, it returns duplicate values caused by these blanks.
This is the function:
Function ConcatUniq(xRg As Range, xChar As String) As String
'updateby Extendoffice
Dim xCell As Range
Dim xDic As Object
Set xDic = CreateObject("Scripting.Dictionary")
For Each xCell In xRg
xDic(xCell.Value) = Empty
Next
ConcatUniq = Join$(xDic.Keys, xChar)
Set xDic = Nothing
End Function
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将唯一值连接到字符串 (UDF)
Concatenate Unique Values to a String (UDF)