使用单元格(x,y)作为输入选择最大值excel

使用单元格(x,y)作为输入选择最大值excel,excel,max,vba,Excel,Max,Vba,如何使用一系列单元格(x,y)作为输入来调用VBA中的Max函数 例如,我有两个变量,m&n,其中n>m 我尝试使用以下代码查找单元格范围内的最大值: Cells(Count, 4) = Application.WorksheetFunction.Max(Cells(m, 1): Cells(n, 1)) 使用该代码,我不断得到一个错误“预期:列表分隔符或” 编辑,这里是完整的代码 Sub convertFNIRStoCandlesticks() 'Variable declarations

如何使用一系列单元格(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

您可以在
应用程序上使用函数
Max
。工作表函数
,其中您可以使用范围从
单元格(m,1)
单元格(n,1)


这将把max返回到
单元格(计数,4)

这样做:
单元格(计数,4)=Application.WorksheetFunction.max(范围(单元格(m,1),单元格(n,1))
我不断得到错误的参数数或无效的参数赋值。有什么想法吗?你复制粘贴了吗?使用我的函数不会出现这样的错误。但是,什么是:
m
n
count
?对C&P来说是的。m是时间窗口开始时的行号,n是时间窗口结束时的行号,count是我将返回值放在哪里的行号。code是正确的-我在下面的答案中看到了相同的结果,因此我确信。这三个变量的当前值是多少?你确定你的错误就在这条线上吗?你能提供更多的宏数据进行分析吗?
Cells(Count, 4)=Application.WorksheetFunction.Max(Range(Cells(m, 1),Cells(n, 1)))