Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:24:46+00:00 2026-06-08T17:24:46+00:00

The percentrank function can take the same named range for both of its agruments

  • 0

The percentrank function can take the same named range for both of its agruments like:

=percentrank(inputrange,inputrange)

It treats the first argument as a range of cells for calculating percent cutoffs, and uses the second argument to return a single cell’s value to rank amongst the cutoffs. The single cell is determined by the row in which the function is entered/called from.

I want to recreate this functionality and use the second range reference to find a single cells value (based on the row the function is entered into). Here’s what I have:

Public Function QUARTILE_RANK(DataRange As Range, RefCell As Range)

If RefCell <> vbNullString Then

    q1 = Application.WorksheetFunction.Quartile(DataRange, 1)
    q2 = Application.WorksheetFunction.Quartile(DataRange, 2)
    q3 = Application.WorksheetFunction.Quartile(DataRange, 3)
    q4 = Application.WorksheetFunction.Quartile(DataRange, 4)

    If (RefCell <= q1) Then QUARTILE_RANK = 1
    If (RefCell > q1) And (RefCell <= q2) Then QUARTILE_RANK = 2
    If (RefCell > q2) And (RefCell <= q3) Then QUARTILE_RANK = 3
    If (RefCell > q3) Then QUARTILE_RANK = 4
Else
    QUARTILE_RANK = vbNullString
End If

End Function

If I pass it the same named range for both arguments, it sees both ranges as arrays of cells. I want it to treat the first argument that way, but find a single cell value using the second argument. That is, I want it to mirror the functionality of the PERCENTRANK function.

EDIT:

Sean Chesire’s input helped me get it working. I’d welcome any suggestions for improvement as I’m sure this same function has been written by others.

Here’s the final form:

Public Function QUARTILE_RANK(DataRange As Range, RefRange As Range)

Dim refCell As Range

If RefRange.Rows.Count > 1 Then
    Set refCell = RefRange.Cells(Application.Caller.Row, 1)
Else
    Set refCell = RefRange ' maybe they only passed a cell reference
End If

If refCell <> vbNullString Then

    q1 = Application.WorksheetFunction.Quartile(DataRange, 1)
    q2 = Application.WorksheetFunction.Quartile(DataRange, 2)
    q3 = Application.WorksheetFunction.Quartile(DataRange, 3)
    q4 = Application.WorksheetFunction.Quartile(DataRange, 4)

    If (refCell <= q1) Then QUARTILE_RANK = 1
    If (refCell > q1) And (refCell <= q2) Then QUARTILE_RANK = 2
    If (refCell > q2) And (refCell <= q3) Then QUARTILE_RANK = 3
    If (refCell > q3) Then QUARTILE_RANK = 4
Else
    QUARTILE_RANK = vbNullString
End If

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:24:48+00:00Added an answer on June 8, 2026 at 5:24 pm

    this will tell you which cell the formula was called from:

    Function testit() As String
    testit = Application.Caller.Parent.Parent.Name & " " & Application.Caller.Parent.Name & " " & Application.Caller.Address
    End Function
    

    You should then be able to test the ranges given, and work out which value should be referenced in the other array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is javascript code, I want to change it into C# code, same as
I have an elementary stumper using serialization in an ASP.NET 2.0 application on a
I updated my main and sequetialSearch and now it crashes when it runs. It
I have a very big table of measurement data in MySQL and I need
Consider the following Python code: In [1]: import numpy as np In [2]: import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.