如何使用一系列单元格(x,y)作为输入调用VBA中的Max函数?
例如,我有两个变量,m& n,其中n>米
我尝试使用以下代码在单元格范围内找到Max值:
Cells(Count, 4) = Application.WorksheetFunction.Max(Cells(m, 1): Cells(n, 1))
使用该代码我一直收到错误"预期:列表分隔符或)"
编辑,这是整个代码
Sub convertFNIRStoCandlesticks()
'Variable declarations
Dim rowCount As Integer 'The total number of rows in use
Dim Count As Integer
Dim Period As Integer
Dim totalPeriods As Integer
Dim PeriodStart As Integer
Dim PeriodEnd As Integer
rowCount = ActiveSheet.UsedRange.Rows.Count
totalPeriods = rowCount / 6
Sheets("Sheet1").Activate
For Count = 1 To totalPeriods
Period = Count - 1
PeriodStart = (Period * 6) + 1
m = (Period * 6) + 1
PeriodEnd = (Period * 6) + 6
n = PeriodEnd
Cells(Count, 2) = Cells(PeriodStart, 1)
Cells(Count, 4) = Application.WorksheetFunction.Min(Range(Cells(PeriodStart, 1), Cells(PeriodEnd, 1)))
Cells(Count, 5) = Cells(PeriodEnd, 1)
Next Count
End Sub
答案 0 :(得分:0)
您可以使用Max
上的Application.WorksheetFunction
功能,Range
使用Cells(m, 1)
到Cells(n, 1)
:
Cells(Count, 4)=Application.WorksheetFunction.Max(Range(Cells(m, 1),Cells(n, 1)))
这会将最大值返回Cells(Count, 4)