我已經編寫了一個程序,該程序一次搜索給定供應商名稱的行,然後從該列中提取該供應商的項目成本。電子表格中的供應商名稱直接從封面上拉出,程序將從同一來源讀取供應商名稱。這個程序有80多個獨立的excel文件,並且幾乎在每個單獨的文件中都能很好地工作。但是,有兩三個人無法找到給定範圍內的任何值,儘管我正在尋找正在嘗試搜索的值。我在Excel中使用find函數手動嘗試,並且無法找到該字符串。什麼可能會阻止Excel找到這些值?VBA查找函數找不到給定值
With Worksheets("Decision Matrix Summary")
m = 0
For Each c In .Range("N23:N42")
If c.Value <= 10 And c.Value > 0 Then
m = m + 1
vendor = c.Offset(0, -13).Value
Worksheets("Supplier Cost Comparison").Cells(2, m + 1) = vendor
Set cell = Worksheets("Bid Tabulation Summary").Rows("9").Find(what:=vendor, after:=Worksheets("Bid Tabulation Summary").Cells(9, 1), _
LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByColumns, searchdirection:=xlNext, _
MatchCase:=False, searchformat:=False)
If Not cell Is Nothing Then
bottomcell = cell.Offset(60000, 0).Address
cell = Worksheets("Bid Tabulation Summary").Range(bottomcell).End(xlUp).Address
Worksheets("Supplier Cost Comparison").Cells(3, m + 1).Value = Worksheets("Bid Tabulation Summary").Range(cell).Value
Else
MsgBox ("A vendor could not be found in the Bid Tabulation Summary. Please refer to the Supplier Cost Comparison tab to determine which vendor.")
Error = "Very Yes"
Exit Sub
End If
Else: End If
Next
End With
任何幫助,非常感謝。謝謝!
編輯:我修好了。我清除了我想要查找值的單元格的格式,然後重新輸入公式。有沒有一種格式可以防止搜索單元格?我設置的功能忽略格式,所以據我所知,這不應該是一個問題。我很感激任何人都有關於此的信息。
最明顯的解釋是,單元格中的值不是您認爲的值。你能提供幾個例子嗎? –
你檢查過任何流氓字符嗎? – nutsch
試試'what:= Trim(vendor)'而不是'what:= vendor'還要檢查'LookIn:= xlValues'到'LookIn:= xlFormulas'是否有區別? –