Excel VBA索引匹配在即时窗口中有效,但在子窗口中无效

Excel VBA索引匹配在即时窗口中有效,但在子窗口中无效,excel,vba,Excel,Vba,我试图循环并索引匹配两个数组,以填充一个数组以返回到工作表 索引匹配在即时窗口中工作正常,但在公共子窗口中不工作 我已经把它分解为匹配和索引,以及一个完整的声明 从即时窗口 debug.print Lev(3,1) Agamemnon debug.Print WorksheetFunction.Match(LuRange(i, 2),Lev(),False) 2994 debug.Print worksheetfunction.Index(luRange,2994,2) Carlos Car

我试图循环并索引匹配两个数组,以填充一个数组以返回到工作表

索引匹配在即时窗口中工作正常,但在公共子窗口中不工作

我已经把它分解为匹配和索引,以及一个完整的声明

从即时窗口

debug.print Lev(3,1)
Agamemnon
debug.Print WorksheetFunction.Match(LuRange(i, 2),Lev(),False)
 2994 
debug.Print worksheetfunction.Index(luRange,2994,2)
Carlos
Carlos
debug.Print application.worksheetfunction.Index(lurange, WorksheetFunction.Match(luRange(i, 2), LeV(), False),2)
Carlos
我的新潜艇

Public Sub FillValues()
' intent of this routine is to fill all the values from level 2 through level 10
Dim TheResult() As Variant
Dim LeV() As Variant
Dim LevLocation As Variant

luRange = Sheet1.Range("VW")
LeV = Sheet1.Range("LeV")

'VW is the named range for the lookup after the first populating lookup is done after NPG and Level 1 are complete
'=INDEX(VW,MATCH(W2,$V:$V,FALSE),2)
c = 24 'represents column X through c=32 which is AF "L10", loop to be created after row loop is complete and working
r = 2   'represents row 2 the start of running through the rows with formula results
rCount = Sheet1.Range("RowCount").value 'The count of rows to be cycled through with results

ReDim TheResult(rCount)

On Error Resume Next

For i = 2 To rCount

    LookingFor = luRange(i, 2)
    
    If LookingFor = "" Or "Not Found" Or WorksheetFunction.IsNA(LookingFor) Then GoTo blank:
    
    LevLocation = Application.WorksheetFunction(luRange(i, 2), LeV(), 0)
    
    TheResult(i) = Application.WorksheetFunction.Index(luRange, LevLocation, 2)
blank:

Next i
欢迎大家批评,我皮肤很厚;)

问候,,
Dane

第一步,在出错时删除
,然后继续下一步
如果LookingFor=“”或LookingFor=“Not Found”…您必须重复条件的左侧。这就是我要查找的结果。令人惊讶的是,这样的情况会被忽略,并产生这样的结果,第一步,在错误恢复时删除
,然后下一步
如果查找=“或查找=“未找到”…
您必须重复条件的左侧。这就是我要查找的结果。令人惊讶的是,这样的事情会被忽略,并产生这样的结果,