Vlookup,excel,错误438“对象不支持这个属性或方法”

我有以下代码:

  • 它应该放在一个名为“Flash”的工作表中,并获得第i个2位数字值,并检索活动单元右侧4列中的值。
  • 然后交换到同一个工作簿上名为“Sheet1”的工作表,并使用“垂直查找”函数来查找检索的值,并将该列右侧的值返回给该单元格。

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

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. 您需要将范围称为Range("A:A")而不是"A:A"
  2. 如果您使用的是VLOOKUP而不是LOOKUP那么您需要引用四列范围, Range("A:D")
  3. 你需要处理你在A中找不到的testing值

下面的代码示例供您调整

 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)` 

对于这场比赛

我认为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