将单元格值添加到一维数组中,并在其中search多个唯一值

第一:我试图做一个searchbutton,如果它find控制值和该特定列中的值匹配,它将ID(“bearpass”)号码添加到一维数组。 此search可能涉及多个列的多个条件(我有一个Bearpass编号,名字和姓氏),并且这些值中的任何一个都是可search的。 由于该数组为每个find的匹配添加了Bearpass编号,因此该数组中可以有多个相同的ID编号。 我想知道如何添加到数组。 我发现我可能需要Redim Preserve为了保持我的数组中的值,同时添加到结束。 这是我的数组声明:

 Dim matchBearpassNumberArray() As Integer 'redim the array with a value to avoid error from Ubound ' dealing with an un-dimensioned array ReDim matchBearpassNumberArray(1 To 1) As Integer 

这里是我的代码控制search:

 If ctrl.Name = "FirstNameTextBox" Then 'If there is at least one match, increment the total number of search criteria found If WorksheetFunction.CountIf(Sheet1.Range("B:B"), Me.FirstNameTextBox.Value) > 0 Then 'B column contains names criteriaNumberMatches = criteriaNumberMatches + 1 'Begin search loop for FirstName uding DoEvents loop rowNumber = 0 Do DoEvents 'increment row number to check next row rowNumber = rowNumber + 1 '1d. look through Bearpass column in that spot itemInReview = Sheets("Students").Range("B" & rowNumber) 'IF it matches, add the BPN of the match to the array. If itemInReview Like ctrl.Value Then 'add the value in matchBearpassNumberArray(UBound(matchBearpassNumberArray)) = Sheets("Students).Range("A" & rowNumber) 'A column contains the bearpass number for that value 'adjust the size of the array ReDim Preserve matchBearpassNumberArray(1 To (UBound(matchBearpassNumberArray) + 1)) As Integer End If 'go back up to DoEvents/ end DoEvents loop for FirstName Loop Until itemInReview = "" Or IsNull(itemInReview) Else: MsgBox "We didn't find any result for the First Name supplied." End If End If 

此外,如果这个matchBearpassNumberArray得到了工作并添加了所需的所有值,我还有另外一个难题:我需要能够search这个数组,并且find所有的实例,其中包含与NumberNumberMatches一样多的Bearpass Numbers。 由于我的search框,就像上面的那个,有一个Bearpass Number,First Name和Last Name,每个block添加它find的每一个匹配的Bearpass编号,如果我search所有这些,我将需要能够计数每个数组中唯一的Bearpass编号,如果他们有多lesscriteriaNumberMatches值,那么我知道我在所有的类别中find匹配。

更改为Collection解决了我的问题。 此外,我填充另一个工作表的ID号码,每当他们得到了一个标准命中,我递增他们旁边的单元格1.最后,如果一个身份证号码旁边有一个单元格与`.value = criteriaNumberMatches'它被复制到一个集合进行打印。 (仍然在最后一部分工作)