VBA PercentRank Using Array of Textbox Values

breynolds0431

Active Member
Joined
Feb 15, 2013
Messages
303
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi. I have a userform that will count occurrences from a sheet based on a few factors, most notably being a date range. The below has a date range of one week in the past to current date. The counts are working as they should. However, I was trying to find a way to rank these countifs. The countifs results currently range from 1 up to 4. The error that's returned is "unable to get the percentrank property of the worksheetfunction class".

Any ideas on how to get this to work in the below or another way to "rank" the countifs results?

VBA Code:
With Me

          .tbL1AsgCnt1.Value = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud1), "#,##0")
          .tbL1AsgCnt2.Value = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud2), "#,##0")
          .tbL1AsgCnt3.Value = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud3), "#,##0")
          .tbL1AsgCnt4.Value = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud4), "#,##0")
          .tbL1AsgCnt5.Value = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud5), "#,##0")
          
          Dim arr: arr = Array(.tbL1AsgCnt1.Value, .tbL1AsgCnt2.Value, .tbL1AsgCnt3.Value, .tbL1AsgCnt4.Value, .tbL1AsgCnt5.Value)

          .tbL1Shr1.Value = Format(1 - WorksheetFunction.PercentRank(arr, .tbL1AsgCnt1.Value), "#0%")
          .tbL1Shr2.Value = Format(1 - WorksheetFunction.PercentRank(arr, .tbL1AsgCnt2.Value), "#0%")
          .tbL1Shr3.Value = Format(1 - WorksheetFunction.PercentRank(arr, .tbL1AsgCnt3.Value), "#0%")
          .tbL1Shr4.Value = Format(1 - WorksheetFunction.PercentRank(arr, .tbL1AsgCnt4.Value), "#0%")
          .tbL1Shr5.Value = Format(1 - WorksheetFunction.PercentRank(arr, .tbL1AsgCnt5.Value), "#0%")

End With
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I figured this out. The array needs to be populated with other variables. Not sure what the rules are about marking your own answer as the answer but think that's necessary so this post doesn't show up in the Unanswered threads.

VBA Code:
          Dim L1AsgCnt1 As Integer: L1AsgCnt1 = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud1), "#,##0")
          Dim L2AsgCnt1 As Integer: L2AsgCnt1 = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud2), "#,##0")
          Dim L3AsgCnt1 As Integer: L3AsgCnt1 = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud3), "#,##0")
          Dim L4AsgCnt1 As Integer: L4AsgCnt1 = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud4), "#,##0")
          Dim L5AsgCnt1 As Integer: L5AsgCnt1 = Format(WorksheetFunction.CountIfs(rnpr, "", Grant, "<>Denied", assDt, ">=" & Date - 7, assDt, "<=" & Date, L1All, Aud5), "#,##0")

          .tbL1AsgCnt1.Value = L1AsgCnt1
          .tbL1AsgCnt2.Value = L2AsgCnt1
          .tbL1AsgCnt3.Value = L3AsgCnt1
          .tbL1AsgCnt4.Value = L4AsgCnt1
          .tbL1AsgCnt5.Value = L5AsgCnt1
          
          Dim arr: arr = Array(L1AsgCnt1, L2AsgCnt1, L3AsgCnt1, L4AsgCnt1, L5AsgCnt1)

          .tbL1Shr1.Value = Format(1 - Application.WorksheetFunction.PercentRank(arr, L1AsgCnt1), "#0%")
          .tbL1Shr2.Value = Format(1 - Application.WorksheetFunction.PercentRank(arr, L2AsgCnt1), "#0%")
          .tbL1Shr3.Value = Format(1 - Application.WorksheetFunction.PercentRank(arr, L3AsgCnt1), "#0%")
          .tbL1Shr4.Value = Format(1 - Application.WorksheetFunction.PercentRank(arr, L4AsgCnt1), "#0%")
          .tbL1Shr5.Value = Format(1 - Application.WorksheetFunction.PercentRank(arr, L5AsgCnt1), "#0%")
 
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top