【问题标题】:Find the maximum in each row在每一行中找到最大值
【发布时间】:2020-06-08 16:19:12
【问题描述】:

我有三列数据:

我想找出每一行的最大值并将其放在相应行的 E 列中。
比如第一行:41.13,第二行:2143.404,以此类推。

Dim LastRowIdent As Long, LastRowCant As Long

With Sheets("LOL")

    LastRowIdent = .Cells(.Rows.Count, 1).End(xlUp).Row
    .Range("A2:A" & LastRowIdent).Copy Destination:=Sheets("Animal").Range("A5") 
    LastRowCant = .Cells(.Rows.Count, 7).End(xlUp).Row
    .Range("G2:G" & LastRowCant).Copy Destination:=Sheets("Animal").Range("B5") 
        
End With
    
Application.DisplayAlerts = False
    
With Sheets("Animal")
        
    Dim NumSheet As Long
    NumSheet = ThisWorkbook.Worksheets.Count - 6
        
    Range("F:F").Copy
    Range("G:G").Resize(, NumSheet).Insert Shift:=xlToRight, Copyorigin:=xlFormatFromLeftOrAbove
            
    Range("E:E").Copy
    vRange("F:F").Resize(, NumSheet).Insert Shift:=xlToRight, Copyorigin:=xlFormatFromLeftOrAbove
        
    Range("C:C").Copy
    Range("D:D").Resize(, NumSheet).Insert Shift:=xlToRight, Copyorigin:=xlFormatFromLeftOrAbove
        
    Dim M As Long
    For M = 1 To NumSheet + 1
        Dim LastRowPrec As Long
        LastRowPrec = ActiveWorkbook.Worksheets(2 + M).Cells(.Rows.Count, 11).End(xlUp).Row - 2
        ActiveWorkbook.Worksheets(2 + M).Range("K2:K" & LastRowPrec).Copy Destination:=.Cells(5, 2 + M)
    Next M
    
End With

【问题讨论】:

  • =MAX(A1:C1)????
  • 是的,但是如何为每一行使用 vba?
  • Range("E1:E24").Formula = "=MAX(A1:C1)"...你尝试了什么?
  • 我的问题是我的范围是Range(.Cells(5, 4 + NumSheet + 1), .Cells(LastRowMax, 4 + NumSheet + 1) 因为我不知道最后一行(在图像中是 24 但在我的情况下不是固定的),其他值取决于其他一些工作表
  • .Rows(1).Address(False, False) 在有问题的范围内?

标签: excel vba max multiple-columns


【解决方案1】:

感谢@BigBen,我正在寻找的行是: Range(.Cells(5, 4 + NumSheet), .Cells(LastRowMax, 4 + NumSheet)).Formula = "=MAX(" & .Cells(5, 3).Address(False, False) & ":" & .Cells(5, 3 + NumSheet).Address(False, False) & ")"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    相关资源
    最近更新 更多