excel - 如何在特定范围内获得小值
问题描述
我想在D 列上的日期中获得第 1、第 2、第 3、...第 n... 个小值。但是有一个特定的类别显示在E 列中。我写了一个代码来获得一个特定的范围调用 p。它正在工作。这意味着当类别 C 时,它仅选择范围内的 C 值。当它等于 F 时,它只得到 F 值。
现在我想获得第一个小值的行号。但是C类它给出了正确的小值。但它变成了 F 类,它再次给出了以前的结果。谁能帮我解决这个问题。?
dim p as range, c as range, i as integer, irow as long
dim ary(1 to 5) as varient
ary(1) = "C"
ary(2) = "F"
ary(3) = "B"
ary(4) = "PC"
ary(5) = "BC"
For i = 1 To UBound(ary)
cat = ary(i)
Set p = Nothing
Set c = Nothing
For Each c In Range("E: E")
If c.Value = cat Then
If p Is Nothing Then
Set p = c.Offset()
Else
Set p = Union(p, c)
End If
End If
Next c
irow = Application.WorksheetFunction.Match(WorksheetFunction.Small(p.Offset(, -1), 1), Range("D:D"), 0)
Cells(4, 12) = Cells(irow, 5)
next i
解决方案
推荐阅读
- java - 使用 FusedLocationProviderClient 请求位置更新不起作用,永远不会调用回调
- sql-server - 从选定的日期范围获取平均小时周期
- java - 通过索引获取值。但功能有限(用户定义的功能)
- visual-studio-2017 - Nuget 包翻倍
- java - 我正在尝试将 ArrayList 传递给 Java 中的方法
- javascript - 如何根据正在使用的 PC 的已知参数将按钮重定向到特定 url?
- android - Android/Retrofit:应用程序不通过 http 进行通信,仅通过 https
- javascript - 循环遍历对象的对象
- php - 如何使用`exec()`在PHP中执行使用`npm`命令安装的命令?
- python - 比较相对和绝对文件路径,仅提取相对部分