Martlark
Martlark

Reputation: 14581

How to pass range to Excel formula from VBA function

I'm writing a function to generate moving averages for smoothing a graph. I need to use quartile ranges to adjust the smoothing formula. How do I pass the QuartileRange to the Evaluate function to return the quartile value of that range so I may use it in my function?

The function is called as follows

=MovingAverageSmoothQuartile( A1, 4, B1:b10 )

Where

Upvotes: 2

Views: 1924

Answers (4)

Dan
Dan

Reputation: 45741

Like this:

q1 = WorksheetFunction.quartile(QuartileRange, 1)

Upvotes: 2

markblandford
markblandford

Reputation: 3193

Not quite sure why you would use Evaluate here? I think you need to do this instead:

ql = WorksheetFunction.Quartile(QuartileRange, 1)

Upvotes: 1

brettdj
brettdj

Reputation: 55672

You can use QUARTILE directly in VBA without EVALUATE.

For example, to return the first quartile from A1:A10:

Sub Calltest()
MsgBox Test([a1:a10])
End Sub

Function Test(rng1 As Range)
Test = Application.WorksheetFunction.Quartile(rng1, 1)
End Function

Upvotes: 1

shahkalpesh
shahkalpesh

Reputation: 33476

q1 = Evaluate("Quartile(INDIRECT(" + QuartileRange.Text + "), 1")

I am sorry, I don't know the use of Quartile function & am assuming that the QuartileRange.Text contains a range address in string form.

Upvotes: 0

Related Questions