I have written the below piece of code in VBA that basically checks if the value in cell B24 is positive and if positive it iterates through a for-loop for 50 times where X0 and sqrt are repeatedly updated.
However when I debug the code it throws an error
'Run-time error '1004'
Application-defined or object-defined error.
I checked the syntax, it looks fine but the error keeps popping. How to resolve this issue? Help pls
Sub forloopCalc()
Dim X0, sqrt As Integer
Dim sheetName As String
sheetName = "Sheet1"
Dim WSD As Worksheet
Set WSD = Worksheets(sheetName)
If (Cells(B, 24).Value > 0) Then
X0 = 5.96046447753906E-08
sqrt = 0.000244140625
For i = 0 To 50
If ((X0 - Cells(B, 24).Value) < 0) Then
X0 = X0 * 4
sqrt = sqrt * 2
Exit For
End If
Next i
End If
WSD.Cells(P, 24).Value = X0
WSD.Cells(R, 24).Value = sqrt
End Sub
Aucun commentaire:
Enregistrer un commentaire