Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA中的VBA多条件搜索_Vba_Excel - Fatal编程技术网

VBA中的VBA多条件搜索

VBA中的VBA多条件搜索,vba,excel,Vba,Excel,我在一张表中列出了大约50万个项目。我需要根据年份和服务代码进行匹配。 我正在尝试使它动态,因为我需要搜索大量的表和行。所以基本上我有: 我宁愿不这样做,但我想不出来。这将为每个“变量”创建一个临时范围。我这样做是因为当我在一个单元格中输入下面的公式时,它是有效的 Sheets("Worker").Range("A1").Name = "yearlk" Sheets("Worker").Range("A2").Name = "svclk" For xlRow = 2 To xlLastRow

我在一张表中列出了大约50万个项目。我需要根据年份和服务代码进行匹配。 我正在尝试使它动态,因为我需要搜索大量的表和行。所以基本上我有:

我宁愿不这样做,但我想不出来。这将为每个“变量”创建一个临时范围。我这样做是因为当我在一个单元格中输入下面的公式时,它是有效的

Sheets("Worker").Range("A1").Name = "yearlk"
Sheets("Worker").Range("A2").Name = "svclk"

For xlRow = 2 To xlLastRow

    Range("yearlk").Value = Cells(xlRow, xlColYear) 'Sets the range to the current year
    Range("svclk").Value = Cells(xlRow, xlServiceCode) 'sets the range to current ServiceCode

    Exists = Evaluate("{=INDEX(vwSVC_RegTool[service_code_id],MATCH(1,(vwSVC_RegTool[term_year]=yearlk)*(vwSVC_RegTool[service_code_id]=svclk),0))}")

next xlRow

让我恼火的是,这一切都在细胞中工作,但我正在制作一个自定义工具,所以它需要从xlam工作

我不知道如何回答上面的问题,但是,我只是将范围设置为一个变量,然后将另一个变量设置为索引,并进行了两次循环,速度非常快

SVCtran = ThisWorkbook.Sheets("CPT Codes and HCPCS").Range("vwSVC_RegTool")
ReDim SVCStor(UBound(SVCtran))
For I = 1 To UBound(SVCtran)
    SVCStor(I) = SVCtran(I, 1)
Next

II = Int(Sqr(UBound(SVCStor))) 'this setups the index size
ReDim SVCIndex(II, 2)
For I = 1 To UBound(SVCIndex) - 1
    SVCIndex(I, 1) = II * I 'set position of index
    SVCIndex(I, 2) = SVCStor(II * I) 'set value of index Start
Next I
SVCIndex(UBound(SVCIndex), 1) = UBound(SVCStor)
然后,xlRow=1到xlLastRow-1的操作索引 对于xlRow到xlLastRow 存在=真 比较=ColValue2(xlRow,1)和ColValue(xlRow,1)


这个想法是,最初它有大约1.6MM的记录要搜索大约10万次。我知道真正的数学家会扼杀我将要说的话,但那大约是平均800亿次搜索。有了这个,我们将1.6M设置为1265大小的1264索引,给出了126MM的平均搜索。。。。疯狂****注意这一定是一个有序的列表

如果我把这一切都搞错了好吧。。。我的主要目标是说。。。年份=2012,SVC=A52453。。。表中是否存在该组合。
    For R = 1 To UBound(SVCIndex) 'find the start and finish of the index
        If SVCIndex(R, 2) > compare And compare >= SVCIndex(R - 1, 2) Then
            Start = SVCIndex(R - 1, 1)
            Ender = SVCIndex(R, 1)
        End If
    Next

    For R = Start To Ender 'set the loop to only look in the index locations
        Exists = False
        If compare = SVCStor(R) Then
            Exists = True
            Exit For
        End If
    Next

    If Exists = False Then
        InvalidFormat(I) = xlRow '2014Z0334
        I = I + 1
    End If

Next