-2

我有一个 Excel 2013 电子表格,其中显示了不同地区资产的收入。

我正在编写一个宏,它将在收入旁边的空白单元格中输入一个日期,如果该收入位于该地区的前 10% 并且最近没有审查。这就是我发现困难的地方。

我可以写一行代码返回收入的前百分之十,但不知道如何返回一个区的前百分之十。

作为一个函数,我可以达到预期的结果如下: {=LARGE(IF(I13:I1000=800,IF(AO13:AO1000<>DATE(2015,3,12),AI13:AI1000,""),""), 17)}

对于我的宏,我编写了以下代码:

1) 接受将审查哪个学区和审查日期的输入

2)确定上次审查的时间(有点,同样的问题,我需要找到某个地区资产的最大值)

3) 计算需要审查的资产数量(前 10% 和后 20%)

这是我到目前为止的代码:

Sub ScheduleNextReview()
'Determine which district will be reviewed
    Dim Dist As String
    Dim NextDate As Date

    Dist = InputBox(Prompt:="Enter district for review:", Title:="Dist:", Default:="000")
    NextDate = InputBox(Prompt:="Date of Review", Title:="Enter Date for next review:", Default:="mm/dd/yyyy")

'Find date of Last Review
    Dim rng As Range
    Dim LastReview As Date
    Set rng = ActiveSheet.Range("AL13:AL1000")
    LastReview = Application.WorksheetFunction.Max(rng) 'need to figure out how to get the max value for those in Dist

'Count number of wells in district and find top ten percent and bottom twenty percent
    Dim DistTtl As Double
    Dim TopTenth As Integer
    Dim BottomTwent As Integer

    DistTtl = WorksheetFunction.CountIf(Range("I13:I10000"), Dist)
    TopTenth = WorksheetFunction.Round(DistTtl / 10, 0)
    BottomTwent = WorksheetFunction.Round(DistTtl / 5, 0)

MsgBox "There are " & TopTenth & " assets in the top ten percent, and " & BottomTwent & " assets in the bottom twenty percent of " & Dist & " for review on " & NextDate & "."
End Sub

我正在努力弄清楚如何使用 IF 语句定义范围或获取与我上面粘贴的函数等效的工作表函数。

如果有任何需要进一步澄清的地方,请告诉我谢谢!

4

1 回答 1

0

我能想到的最好的解决方法是使用如下函数: {=PERCENTILE.INC(IF(I13:I999=100,AI13:AI999,""), 0.9)}

我为每个地区执行了这个函数,然后创建了一系列 ElseIf 语句来获得所选地区的第 90 个百分位数:

            Dim Dist90 As Double
            Dim Dist As Integer

        If Dist = 100 Then
            Dist90 = Cells(2, 48)
        ElseIf Dist = 200 Then Dist90 = Cells(3, 48)
        ElseIf Dist = 300 Then Dist90 = Cells(4, 48)
        ElseIf Dist = 400 Then Dist90 = Cells(5, 48)
        ElseIf Dist = 500 Then Dist90 = Cells(6, 48)
        ElseIf Dist = 600 Then Dist90 = Cells(7, 48)
        ElseIf Dist = 700 Then Dist90 = Cells(8, 48)
        ElseIf Dist = 800 Then Dist90 = Cells(9, 48)
        End If
于 2015-07-21T13:56:06.907 回答