列范围的最大值

时间:2018-06-05 15:30:03

标签: excel vba excel-vba

需要一些帮助来确定列范围的最大值。应该很容易,但我的列范围由字符串确定,该字符串用于计算工作表上现有行的总数。

我在下面的代码中尝试了这些方法,但只是在指定的单元格中返回#NAME?

由于

With ThisWorkbook.Sheets("API-VAL")
LastRow = Range("A1").End(xlDown).row ' Determins the last row from previous populated calulation
.Range("BW1").Value = "=worksheetfunction.Max(BU1:BU & LastRow)"
.Range("BX1").Formula = "=Max(BU1:BU & CStr(LastRow))"
.Range("BY1").Formula = "=Min(BU1:BU & LastRow)"
End With

2 个答案:

答案 0 :(得分:0)

您需要从引号内删除LastRow(它是否需要该行中的点?),因为“工作表”不知道这意味着什么。

.Range("BW1").Formula = "=Max(BU1:BU" & LastRow & ")"

答案 1 :(得分:0)

如果您不希望粘贴在单元格中的公式,也可以尝试此格式。这只会给你单元格中的值

.Range("BW1") = Application.WorksheetFunction.Max(Range("BU1:BU" & LastRow))
.Range("BY1") = Application.WorksheetFunction.Min(Range("Bu1:BU" & LastRow))