【问题标题】:vba get list without duplicates from listobjectvba从listobject获取没有重复的列表
【发布时间】:2018-04-26 00:56:39
【问题描述】:

是否有 vba 命令可以直接从列表对象的标头 autofilter 中获取不重复的列表。

我的输入是this list,我搜索了一种方法来获取此列表,而不会从我在 vba 中的对象 ListObject 中重复

提前致谢。

【问题讨论】:

标签: vba


【解决方案1】:

你可以使用这个 helper 功能:

Function GetUniqueValues(rng As Range) As Variant
    Dim cell As Range

    With CreateObject("Scripting.Dictionary")
        For Each cell In rng
            .Item(cell.Value) = 1
        Next
        GetUniqueValues = .keys
    End With
End Function

由您的“主”模块调用,如下所示:

Option Explicit

Sub main()
    Dim uniqueValues As Variant

    uniqueValues = GetUniqueValues(ActiveSheet.ListObjects(1).ListColumns(1).DataBodyRange)

    '... rest of your code
End Sub

只需根据您的需要更改 ActiveSheetListObjects(1)ListColumns(1) 引用

【讨论】:

  • 非常感谢您的回答
猜你喜欢
  • 2018-12-31
  • 2021-05-04
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-18
  • 2013-09-15
相关资源
最近更新 更多