我的问题是关于根据属性字段过滤 vba 集合或字典。我使用 VBA 来处理一堆数据提取,并为此目的提供了一系列自定义的类对象。一旦定义了它们并将它们填充到集合或字典中,我需要根据各种属性选择这些对象的子集。我的问题是,是否有比简单循环并测试条件更有效的方法?
下面是一些基本代码来说明问题。由于我的工作场所政策,我什至无法上传示例 Excel 文件,但数据并不真正相关。我的测试文件只是一堆 rand Between 函数,例如 '=choose(rand Between(1,3),"red","green","blue")
'Simple Class definition
Option Explicit
'very simple test class
'One field is unique, the other three are simple strings that
'fall into groups (I don't always know what the groups will bee)
Private m_uniqueID As String
Private m_strTest1 As String
Private m_strTest2 As String
Private m_strTest3 As String
Public Property Get uniqueID() As String: uniqueID = m_uniqueID: End Property
Public Property Let uniqueID(ByVal NewValue As String): m_uniqueID …Run Code Online (Sandbox Code Playgroud)