VBA应用程序定义或对象定义的错误

我正在使用Excel的VBA。 每次运行此代码时,都会收到“应用程序定义的或对象定义的”错误。 这里是:

Sub Test() Dim i As Integer, j As Integer, k As Integer, l As Integer, t As Integer Dim row As Integer Dim Maturite As Integer Dim tsup As Double, tinf As Double Dim datetaux As Date, datejouissance As Date Dim taux As Double For i = 2 To 770 Maturite = Sheets("Em").Cells(i, 19) datejouissance = Sheets("Em").Cells(i, 14) For l = 2 To 255 For k = 0 To 10 For t = 1 To 10 row = 13 * k + 2 datetaux = Sheets("TSR").Cells(row, l) taux = Sheets("TSR").Cells(13 * k + 3, l) If taux <> 0 Then If datejouissance = datetaux Then If 91 <= Maturite And Maturite <= 182 Then tsup = Sheets("TSR").Cells(row + 2, j) tinf = Sheets("TSR").Cells(row + 1, j) Sheets("Em").Cells(i, 21).Value = ((tsup - tinf) * (Maturite - 91) / (182 - 91)) + tinf End If End If End If Next Next Next Next End Sub 

我得到的错误在:

  tsup = Sheets("TSR").Cells(row + 2, j) 

我试过使用:

  tsup = Sheets("TSR").Cells(row + 2, j).Value 

表格的types(“TSR”)。单元格(行+ 2,j)。值是双精度型。 但它不工作。 我似乎无法理解问题是什么。

提前致谢

我想你可能需要检查j的值。 据我可以看到你的代码,它的值仍然是0.列0不存在,将导致给定的错误。

您使用整数j对单元格进行寻址,但不要为j赋值。 因此,VBA填充整数的标准值: 0 ,将你的调用指向Sheets("TSR").Cells(row + 2, 0)并产生一个错误。