1

如何使用一系列单元格(x,y)作为输入在 VBA 中调用 Max 函数?

例如,我有两个变量 m & n,其中 n > m

我尝试使用以下代码在一系列单元格中找到最大值:

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
4

1 回答 1

0

您可以MaxApplication.WorksheetFunction使用Rangefrom Cells(m, 1)to的位置使用该功能Cells(n, 1)

Cells(Count, 4)=Application.WorksheetFunction.Max(Range(Cells(m, 1),Cells(n, 1)))

这将返回最大值Cells(Count, 4)

于 2013-06-19T18:36:45.493 回答