我有一个 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 语句定义范围或获取与我上面粘贴的函数等效的工作表函数。
如果有任何需要进一步澄清的地方,请告诉我谢谢!