Thank you for your reply and sorry for such a delay in getting back to you.
This code works as desired for that purpose.
Sub test() Dim V As Double lastrow = Cells(Rows.Count, "A").End(xlUp).Row inarr = Range(Cells(1, 1), Cells(lastrow, 3)) For i = 2 To lastrow V = inarr(i, 3) Cells(i, 7) = X(V) Next i Worksheets(1).Range("G1").Value = "dP / L" End Sub Function X(V As Double) As Double X = V * Worksheets(1).Range("E2") / Worksheets(1).Range("D2") End Function 'Here the constant values are brought from the worksheet, whilst the variable input is still accounted for.
For a similar situation, but for one where there is only one variable, is the above code as efficient/correct as it could be?
Here column C has the rising values for V, but column A, B, D, E etc contain constants.
This code works with this set up.
However, I have applied it to another scenario on another worksheet and it does not run.
Here, the varying input is in column J starting at row 4. The constants have been inputted manually.Sub test2() Dim Nr As Double lastrow = Cells(Rows.Count, "A").End(xlUp).Row inarr = Range(Cells(1, 1), Cells(lastrow, 10)) For i = 4 To lastrow Nr = inarr(i, 10) Cells(i, 16) = DIP(Nr) Next i End Sub Function DIP(Nr As Double) As Double DIP = 1 + ((1.996 * 5) / Nr) End Function
Thanks,
ITY




Reply With Quote
