hello,

I have following code which I want to make to work whenever I select ExponentialDeclineA. The code works return a correct value but only works if my data is in the correct cells that code is looking for.

question:

in this "n = .Cells(.Rows.Count, "B").End(xlUp).Row" can I remove "B" and refer to x,y,w which I define when I use ExponentialDeclineA in excel?
Also how can I change Cells(5 + i, 2) so that 5 and 2 replaced with first row and column of range x which I select when I use ExponentialDeclineA in excel.

Function ExponentialDeclineA(x, y, w As Range)

With ActiveSheet
n = .Cells(.Rows.Count, "B").End(xlUp).Row
End With

A = 0
B = 0
C = 0
D = 0
E = 0
F = 0

For i = 1 To n

If Cells(5 + i, 2) = "" Or Cells(5 + i, 3) = 0 Then GoTo Lastline Else GoTo Line1

Line1:

A = Cells(5 + i, 2) * Cells(5 + i, 2) * Cells(5 + i, 4) + A
B = Cells(5 + i, 4) * Log(Cells(5 + i, 3)) + B
C = Cells(5 + i, 2) * Cells(5 + i, 4) + C
D = Cells(5 + i, 2) * Cells(5 + i, 4) * Log(Cells(5 + i, 3)) + D
E = Cells(5 + i, 4) + E
F = Cells(5 + i, 2) * Cells(5 + i, 4) + F

GoTo Lastline:

Lastline:

Next i

ExponentialDeclineA = Exp((A * B – C * D) / (E * A – F * F))

End Function