I would like to return the value of compZ into my excel data sheet. If you could tell me how to do so, I would really appreciate it.
The code is attached below:
Option Explicit
Option Base 1
Public Function valZ120() As Double
'declare variables
Dim equation As Double
Dim x As Double
Dim randint As String
Dim compZ(476) As Double
Dim derEq As Double
Dim valX As Double
Dim nvalX As Double
Dim varA As Double
Dim varB As Double
Dim i As Double
'loop from i=25 to i=500
For i = 25 To 500
varA = (0.538083613 * 13736.62195 * i) / ((8.3145 ^ 2) * (120 ^ 2))
varB = (2.528160538 * i) / (8.3145 * 120)
x = 0
nvalX = 0.2
'a Do While loop
Do While Abs(nvalX - x) >= (0.01)
x = nvalX
equation = (x ^ 3) - (x ^ 2) + (x * (varA - varB - varB ^ 2)) - (varA * varB)
derEq = (3 * x ^ 2) - (2 * x) + (varA - varB - varB ^ 2)
nvalX = (x) - ((equation) / (derEq))
Loop
'once the do while loop is complete, the value obtained is stored in the first space in the array and so on
compZ(i - 24) = nvalX
'this was just to test the code to make sure it was working (it is)
MsgBox compZ(i - 24)
Next
'how do I bring the values of this array into excel?
End Function
Thank You