0
我有一些代碼查看工作表。此代碼應查看列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
但不觸發每個Bearpass數的要被添加到matchBPNcol
VBA'And'運算符是'And':)...在這一行出錯了'如果Len(cellNextDoor)<> 0&cellNextDoor = criticaNumberMatches Then''。 '&'用於將字符串連接在一起 – Rosetta
賓果。感謝您的幫助!後來我在關於關係運營商的MS文檔中屢屢發現了這一點。 你是一個出色的人!謝謝你! – Sean
指揮官,我們已經找到你的&!! XD – Rosetta