检查附近的小区是否匹配

时间:2015-11-28 03:52:49

标签: excel vba excel-vba

我有一些代码可以查看工作表。此代码应查看A列中具有值的所有项,然后查看右侧的一列,以查看B列中的邻居是否具有值。如果B中的值存在,AND与某个标准编号匹配,则A列中的值将被复制到集合中(作为ID以便稍后显示详细信息)。

 If criteriaNumberMatches > 0 Then
'Dim Element As Integer
'goal is to count the number of each unique Bearpass Number, and if its > 3 display user info

Dim totalCorrectHits As Integer

'THIS MAY NOT WORK
'look through the rows of the Extra Interface
For Each cell In Sheet4.Range("A2:A1000")
    If Len(cell.Value) <> 0 Then
        cellNextDoor = cell.Offset(rowOffset:=0, columnOffset:=1)
        'check to see if cell to the right has a value equal to the criteria matches
        If Len(cellNextDoor) <> 0 & cellNextDoor = criticaNumberMatches Then
            matchBPNcol.Add cell.Value
            totalCorrectHits = totalCorrectHits + 1
            MsgBox "Commander, we've found something!"
        'old code below
        'MsgBox cell.Value & "is the cell value, vs " & criteriaNumberMatches & " matches "
            'if the criteria hits = the number of criteria, add to collection
            'If cell.Value = criteriaNumberMatches Then
               'Look one cell left to find the BPN, and add it
               'thingToAdd = ActiveCell.Offset(rowOffset:=0, columnOffset:=1)
               'THIS ALSO MAY NOT WORK
               'matchBPNcol.Add thingToAdd
               'totalCorrectHits = totalCorrectHits + 1
            End If
    End If
Next
Else: MsgBox "No Results Found"
End If
        MsgBox "There are " & criteriaNumberMatches & " criteria to match"
        MsgBox "The matchBPNcol contains " & matchBPNcol.Count & " positive matches in all criteria"
        MsgBox "There are " & totalCorrectHits & " totally unique BPN matches"

因此,最后,我注意到我的收藏集(matchBPNcol)为空,我的totalCorrectHits也是空的。我可能错误地将单元格定义为右侧。 下面的图片是criteriaNumberMatches = 2的示例,但它不会触发要添加到matchBPNcol的每个Bearpass数字

Example of criteriaNumberMatches = 2, should trigger hits

1 个答案:

答案 0 :(得分:0)

感谢KS Sheon的回答:我的逻辑If Len(cellNextDoor) <> 0 & cellNextDoor = criticaNumberMatches Then在需要&时包含And。第一个是关系,第二个是串联。