excel - 在 Vba 列的范围内查找最小值和最大值
问题描述
我一直在尝试查找列的最小值和最大值,但似乎无法让我的代码正常工作。我已经尝试过 if 语句,for 循环,但似乎无法使其工作。我也一直在使用 application.worksheetfunction.min/max 并且无法正常工作。
Sub MinMax()
Dim xmax As Double
Dim xmin As Double
Dim TableRow As Integer
For i = 2 To lastrow
If cells("i,11").Value < cells(i + 1, 11).Value Then
xmin = cells(i, 11).Value
cells(3, 16).Value = xmin
End If
If cells(i, 11).Value > cells(i + 1, 11).Value Then
cells(2, 16).Value = xmax
End If
Next i
End Sub
解决方案
试试这个:
Sub MinMax()
Dim xmax As Double
Dim xmin As Double
Dim r As Range
Set r = Range("K2:K" & Rows.Count)
xmin = Application.WorksheetFunction.Min(r)
xmax = Application.WorksheetFunction.Max(r)
End Sub
推荐阅读
- javascript - 如何在 TypeScript 中比较 2 个布尔值
- typescript - 如何扩展原生 window.Notification 来处理点击事件(TypeScript 4.1.2)
- java - Pdfbox 签名 - saveIncremental 与 saveIncrementalForExternalSigning
- node.js - 如何在云函数中进行日期数学运算
- android - 如何在 OpenGL Android 中同时实现亮度和对比度过滤器?
- python - 如何在 Django 会话中存储表单cleaned_data
- c# - 在第二个依赖于第一个时执行异步任务
- python - Python Selenium - 自动点击登录网页不起作用
- ios - Firebase 在类型转换方面表现得很奇怪
- javascript - JavaScript数组中推送和赋值的区别