Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 查找满足条件的第一个集合_Excel_Vba - Fatal编程技术网

Excel 查找满足条件的第一个集合

Excel 查找满足条件的第一个集合,excel,vba,Excel,Vba,我有一个具有二进制属性的集合对象。它是一个二维格式的集合 Dim colArry(1 to 5, 1 to 3) as New Collection 集合的二进制属性如下所示: 1 2 3 1 0 0 0 2 0 0 1 3 1 0 0 4 0 0 0 5 0 0 0 集合属性存储为: Dim pNumber as Integer Public property Get() as Intege

我有一个具有二进制属性的集合对象。它是一个二维格式的集合

Dim colArry(1 to 5, 1 to 3) as New Collection 
集合的二进制属性如下所示:

   1    2    3
1  0    0    0
2  0    0    1
3  1    0    0
4  0    0    0
5  0    0    0
集合属性存储为:

Dim pNumber as Integer    

Public property Get() as Integer
    Number = pNumber
End property
Public property Let Number(value as Integer)
    pNumber = value
End Property 
我想将属性为1的第一行(跨所有列)的集合引用存储在新变量中

在上面的集合中,我想标记
colArray(2,3)
。如果第3列都是零,那么我想标记
colArray(3,1)

我想通过将行和列索引存储在两个变量中来标记这一点:
row=2
col=3

该属性从Excel工作表中读取,例如从工作表1上的单元格R1C1开始:

for i=1 to 5 
    for j=1 to 3
        colArray(i,j) = ThisWorkbook.Sheets("Sheet1").Cells(i,j)
    Next j
Next i
以下是一个例子:

Option Explicit

Public Sub Example()
    'fill an example array
    Dim ColArray(1 To 5, 1 To 3) As Integer
    ColArray(2, 3) = 1
    ColArray(3, 1) = 1

    'now the ColArray looks like
    '0   0   0
    '0   0   1
    '1   0   0
    '0   0   0
    '0   0   0

    Dim Found As Boolean
    Dim iRow As Long, iCol As Long
    For iRow = LBound(ColArray, 1) To UBound(ColArray, 1) 'loop throug rows
        For iCol = LBound(ColArray, 2) To UBound(ColArray, 2) 'loop throug columns
            If ColArray(iRow, iCol) = 1 Then 'check if value is 1
                Found = True
                Exit For
            End If
        Next iCol
        If Found Then Exit For
    Next iRow

    'found at ColArray(iRow, iCol)
    If Found Then
        Debug.Print "Found at:", iRow, iCol
    Else
        Debug.Print "not 1 found"
    End If
End Sub
请注意,您可以一次将范围读入数组(无需循环)


您的类模块的名称是什么?你能提供一个例子让我们看看你的数组是如何充满数据的吗?类模块表示一个人有多少可用的约会,我想找到最早的约会。1-5是天,1-3是不同的人。在所有“人”中,我希望找到最低的行=1。
Dim colArray As Variant
colArray = ThisWorkbook.Worksheets("Sheet1").Range("A1:C5").Value