简体   繁体   中英

VBA Application-defined or object-defined error

I am working with VBA for Excel. I get the "Application defined or object defined" error each time I run this code. Here it is:

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

I get the error at :

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

I tried using :

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

The type of Sheets("TSR").Cells(row + 2, j).Value is Double. But it's not working. I can't seem to understand what the problem is.

Thanks in advance

I think you may need to check the value of j. As far as I can see from your code its value remains 0. Column 0 does not exist and will lead to the given error.

You address the cell using the integer j , but you don't assign a value to j . Thus, VBA fills it with the standart value for integers: 0 , directing your call to Sheets("TSR").Cells(row + 2, 0) and producing an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM