[英]Find cell with max value of column, copy entire row and paste in row 2
I have searched the web for an answer for this but can't translate the answers I find into exactly what I want to do. 我已经在网上搜索了有关此问题的答案,但是无法将找到的答案完全转换为我想做的事情。
I want to find the cell in Range("L5:L" & LastRow) with maximum value, and copy that entire row and paste it on row 2. 我想在Range(“ L5:L”&LastRow)中找到具有最大值的单元格,然后复制整个行并将其粘贴到第2行。
I know the code to get the maximum value into cell L4. 我知道将最大值存入单元格L4的代码。 But I also want to copy the row which the maximum value is in. That code is below.
但是我也想复制最大值所在的行。下面的代码。 But how to select and copy the entire row?
但是如何选择并复制整个行呢? Seems like such a simple thing, and I can't get it to work.
似乎很简单,但我无法使其正常工作。
So this is what I have to get the value: 所以这就是我要获得的价值:
Range("L4").Value = Application.WorksheetFunction.max(Range("L5:L" & LastRow))
The following will find the max value, find the first row with the max value, and take row values from the max value row and populate row 2 with the results. 下面将找到最大值,找到具有最大值的第一行,并从最大值行中获取行值,并在结果中填充行2。
Dim lngRow As Long
Dim lngMax As Long
Dim rngTemp As Range
Dim rngCell As Range
Dim lastRow As Long
lastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set rngTemp = Range("L5:L" & lastRow)
lngMax = Application.WorksheetFunction.Max(Range("L5:L" & lastRow))
For Each rngCell In rngTemp
If rngCell.Value = lngMax Then
lngRow = rngCell.Row
Exit For
End If
Next rngCell
Rows(2).Value = Rows(lngRow).Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.