2

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

  • A1 is the value to smooth,
  • 4 is the number of values to use and
  • B1:B10 is a column of samples used to calculate the quartile value.

    Function MovingAverageSmoothQuartile(r As Range, ByVal m As Integer, QuartileRange As Range)
    ' returns a smoothed average using the 'rectangular' method
    Dim q1 As Double, q2 As Double, q3 As Double        
    q1 = Evaluate("Quartile( " + QuartileRange.Text + ", 1") ' <--- Stuck here
    
3
  • What does QuartileRange.Text contain? Commented Oct 5, 2012 at 7:24
  • Should you not use & to concatenate the strings rahter than + ? Commented Oct 5, 2012 at 7:33
  • Thank you to all who answered. When I get back to work I'll implement your suggestions. Commented Oct 5, 2012 at 9:20

4 Answers 4

2

Like this:

q1 = WorksheetFunction.quartile(QuartileRange, 1)
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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

ql = WorksheetFunction.Quartile(QuartileRange, 1)

Comments

0
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.