2012-02-12 350 views
4

我有以下代码:VLOOKUP,EXCEL,错误438“对象不支持此属性或方法”

  • 它应该进入一个名为“闪电侠”片,并获得第i个2位数字值,并检索活动单元右侧偏移4列中的值。
  • 然后交换到同一工作簿中名为“Sheet1”的工作表,并使用垂直查找功能查找检索值并将该值返回到该单元右侧的4列。

但是当我运行它下面的脚本停止工作在:

MsgBox (ActiveSheet.VLookup(LookFor, "A:A", 4, True))

和VBA抛出error 438 object doesn't support this property or method

没有人知道为什么有一个例外?

' Begin lookup : 
Dim i As Integer, designator As String, LookFor As String 
Flash.Activate 
ActiveSheet.Range("C3").Select 
For i = 3 To lastUsedCellInRow("C") 
    designator = "C" + CStr(i) 
    Dim cellVal As String 
    cellVal = ActiveSheet.Range(designator).Value() 
    If (Len(cellVal) <= 2 And IsNumeric(cellVal)) Then 
     LookFor = ActiveSheet.Range(designator).Offset(0, 4).Value() 
     RawData.Activate 
     MsgBox (ActiveSheet.VLookup(LookFor, "A:A", 4, True)) 
    End If 
Next i 
+1

'activesheet.worksheetfunction.vlookup' – 2012-02-12 00:04:45

+0

@TomIngram嗯...这听起来像它可以工作,但是当我代替我的方法与它仍返回'438'错误... – franklin 2012-02-12 00:20:39

+0

尝试'Application.WorksheetFunction .V Lookup' – Cutter 2012-02-12 01:10:54

回答

4

你有几个问题

  1. 您需要参考范围为Range("A:A")"A:A"
  2. 如果使用VLOOKUP,而不是LOOKUP然后根据说明你需要提及的四列范围,Range("A:D")
  3. 您需要处理您的测试值不在A中找到
0123下面

示例代码为您适应

Dim strLookfor as String 
Dim strOut 
strLookfor = "test" 
strOut = Application.VLookup(strLookfor, Range("A:D"), 4, True) 
If IsError(strOut) Then 
    MsgBox "value not found" 
Else 
'return column D value as string 
    MsgBox CStr(strOut) 
End If 

后续

是的,你可以使用

`strOut = Application.VLookup(strLookfor & "*", Range("A:D"), 4, True)` 

这场比赛

BU我觉得Find是清洁剂,即

Dim strLookfor As String 
strLookfor = "F71" 
Dim rng1 As Range 
Set rng1 = Sheets("Sheet1").Columns("A").Find(strfolder & "*", , xlValues, xlPart) 
If Not rng1 Is Nothing Then 
    MsgBox "Match in " & rng1.Offset(0, 3) 
Else 
    MsgBox strfolder & "*" & vbNewLine & "not found" 
End If 
+0

就像后续一样,Vlookup是否会将搜索“F71”与包含字符串“F71 - 更多无意义追随”的数据点进行精确匹配? – franklin 2012-02-12 03:25:35

+1

@franklinchou查看更新评论 – brettdj 2012-02-12 03:35:53

+0

最后只是使用for循环Mid()和Len()函数来查找我正在查找的术语。将尝试这种方法。非常感谢@brettdj – franklin 2012-02-15 21:00:14

相关问题