时间:2015-09-18 10:17:12

标签: excel vba excel-vba

我正在尝试从范围中找到最高值并将该值粘贴到单元格中。我需要从H5开始并向下移动到最后一个值(长度变化)。到目前为止,我一直在使用这段代码:

    With ActiveWorkbook.Sheets("Log")


PressureMax = Application.WorksheetFunction.Max(Range("H5:H" & LastRow))

Sheets("Info").Select
Range("E4").Select
Selection.Formula = PressureMax

End With

然而,它返回的最高值始终为0.“LastRow”为:

Set sht = ThisWorkbook.Worksheets("Log")

LastRow = sht.Cells(sht.Rows.Count, "E").End(xlUp).Row

这会是我的问题吗,但是在我的代码中还有其他用处吗?

1 个答案:

答案 0 :(得分:0)

我已经设法用这段代码回答了我自己的问题:

    With ActiveWorkbook.Sheets("Log")
Dim rng As Range
Dim pressuremax As Double

Set rng = ActiveWorkbook.Sheets("Log").Range("H5:H" & LastRow)

pressuremax = Application.WorksheetFunction.Max(rng)

Sheets("Info").Select
Range("E4").Select
Selection.Formula = pressuremax