运行时13types不匹配

执行下面的代码时,运行时错误13

Dim sh, shmem As Worksheet Dim rw As Range Set shmem = Sheets("SHEET1") Set sh = Sheets("SHEET2") For Each rw In sh.Rows If sh.Cells(rw.Row, 1).Value = "" And sh.Cells(rw.Row, 2).Value = "" Then Exit For End If With Application.WorksheetFunction Dim bdaytest As Variant Dim match1 As Double bdaytest = .Index((shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)) * (shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)), 0) 'match1 = .Match(1, .Index((shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)) * (shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)), 0), 0) bdaytest = .Index(1, shmem.Range("D2:D121"), match1) End With Next rw 

错误发生在我从2行提取的下一行(现在注释掉)

 bdaytest = .Index((shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)) * (shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)), 0) 'match1 = .Match(1, .Index((shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)) * (shmem.Range("A2:A121") = sh.Cells(rw.Row, 1)), 0), 0) 

我明白,错误必须发生,因为bdaytest是错误的数据types,但我不知道,到现在我找不到任何解决scheme。 在此先感谢您的任何build议。

编辑:我想找出2行(A和B)有一个请求值的行的行号。 请求的值在sh.Cells(rw.Row, 1)sh.Cells(rw.Row, 2)

你不能像在公式中那样使用VBA中的=*来创build数组。 你可以做的是使用Application.Countifs像这样:

 Dim sh As Worksheet Dim shmem As Worksheet Dim rw As Range Set shmem = Sheets("SHEET1") Set sh = Sheets("SHEET2") For Each rw In sh.Rows If sh.Cells(rw.Row, 1).Value = "" And sh.Cells(rw.Row, 2).Value = "" Then Exit For End If With Application Dim bdaytest As Variant Dim match1 As Double bdaytest = .Match(1, .CountIfs(sh.Cells(rw.Row, 1), shmem.Range("A2:A121"), _ sh.Cells(rw.Row, 2), shmem.Range("B2:B121")), 0) If Not IsError(bdaytest) Then bdaytest = shmem.Range("D2:D121").Cells(bdaytest) End With Next rw 

注意: WorksheetFunction.Countifs不起作用。