I have a routine which is used to generate time values based on the probability of observing one of two events. Becasue the times are being generated from an inverse exponential distribution by generating a uniform random variable and then solving the equation U=1e^(lambda*x) in terms of x. I am left with having to generate x by using the 'Range.select  Activecell.formula' format which can be quite slow when thousands of variables are generated. Therefore my question is, is there anyway to define the LN function so I can use it without having to select the range. I am finding it a little strange that excel gave me an error when I tried to use the formula using just variables.
Announcement
Collapse
No announcement yet.
LN function in VBA
Collapse
X

Re: LN function in VBA
Not too sure what you really need but you can pass a cells formula, or result of via either of the 2 methods below;
Code:myVariable=Sheet1.Range("A1").formula 'OR myVariable=Sheet1.Range("A1")
Code:WorksheetFunction.LN

Re: LN function in VBA
VBA has its own natural log function, Log. It should be more efficient to use it rather than referring to the worksheet function if you are making many calls.Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.
Comment
Comment