What am I doing wrong?
I'm only really familiar with coding in Matlab, and am having to convert a file from that into VBA. The point is to read an array of numbers (as seen defined in the top), and calculate the different Q values based on the if loops. This is what I have so far, and cannot get any output function to send the calculated Q values back to the worksheet, so currently I don't have one listed. Ideally, I'd like the output to be three columns, one for the number of iterations (i), one for the t value, and one for the Q calculated. Any advice would be great. I've attached my code for reference:
Sub Test2()
Dim i As Integer
Dim t() As Variant
Dim Q As Variant
t = Range("A2:A30")
n = Count 'A2:A30'
For i = 1 To n
If t(i) < 10 Then
Q = 3.67 * t(i) ^ 2 + 3.5
ElseIf t(i) >= 10 Then
Q = 0.76 * Exp(t(i)) + 3.6 * t(i) ^ 1.3
ElseIf t(i) >= 20 Then
Q = 765.1 * Sin(t(i)) + 0.76 * t(i) ^ 0.5
ElseIf t(i) >= 30 Then
Q = 3.11 * (t(i) ^ 0.25 / Application.WorksheetFunction.Ln(t(i))) + 0.13 * t(i) ^ 0.167
End If
Next i
End Sub
cells are referenced and you need to tell macro where to put out
cells are referenced (row,column), so if you want to populate column c of row 10, it would be
Cells(10,3) = "whatever you want putting in that cell"