我已经编写了一个程序,该程序一次搜索给定供应商名称的行,然后从该列中提取该供应商的项目成本。电子表格中的供应商名称直接从封面上拉出,程序将从同一来源读取供应商名称。这个程序有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'是否有区别? –