excel vba - VBA - Top 10 percent of each region -


i have excel 2013 spreadsheet that, among other things, shows income assets in different districts.

i'm writing macro enter date in empty cell next income if income in top 10 percent district , not reviewed. , that's i'm finding difficulty.

i can write line of code return top ten percent of income, can't figure out how return top ten percent of 1 district.

as function, can achieve desired result follows: {=large(if(i13:i1000=800,if(ao13:ao1000<>date(2015,3,12),ai13:ai1000,""),""), 17)}

for macro, have written code will:

1) accept input district reviewed , date of review

2) determine when last review conducted (kind of, same problem, need find max assets in district)

3) calculate how many assets need reviewed (top ten percent , bottom twenty percent)

this code have far:

sub schedulenextreview() 'determine district reviewed     dim dist string     dim nextdate date      dist = inputbox(prompt:="enter district review:", title:="dist:", default:="000")     nextdate = inputbox(prompt:="date of review", title:="enter date next review:", default:="mm/dd/yyyy")  'find date of last review     dim rng range     dim lastreview date     set rng = activesheet.range("al13:al1000")     lastreview = application.worksheetfunction.max(rng) 'need figure out how max value in dist  'count number of wells in district , find top ten percent , bottom twenty percent     dim distttl double     dim toptenth integer     dim bottomtwent integer      distttl = worksheetfunction.countif(range("i13:i10000"), dist)     toptenth = worksheetfunction.round(distttl / 10, 0)     bottomtwent = worksheetfunction.round(distttl / 5, 0)  msgbox "there " & toptenth & " assets in top ten percent, , " & bottomtwent & " assets in bottom twenty percent of " & dist & " review on " & nextdate & "." end sub 

i'm struggling figure out how define range if statement or worksheetfunction equivalent of function pasted above.

please let me know if requires further clarification thanks!

the best work around come use function like: {=percentile.inc(if(i13:i999=100,ai13:ai999,""), 0.9)}

i did function each district , created series of elseif statements 90th percentile chosen district:

            dim dist90 double             dim dist integer          if dist = 100             dist90 = cells(2, 48)         elseif dist = 200 dist90 = cells(3, 48)         elseif dist = 300 dist90 = cells(4, 48)         elseif dist = 400 dist90 = cells(5, 48)         elseif dist = 500 dist90 = cells(6, 48)         elseif dist = 600 dist90 = cells(7, 48)         elseif dist = 700 dist90 = cells(8, 48)         elseif dist = 800 dist90 = cells(9, 48)         end if 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -