首页 > 解决方案 > 如何从列中获取最高值的列表?

问题描述

我有一张表,其中前两列有行和列地址,第三列有整数值。

我想从第 1 列和第 2 列中提取最高值及其对应的地址到工作表上的单独列表中。

第三列中可能有多个相等的最高值。我如何将所有这些都放入我的列表中。

我是 Excel VBA 的新手。

标签: excelvbahighest

解决方案


这可能是一个开始。

Sub maxIntAndOtherStuff()
    Dim rng As Range, c As Range, i As Integer, x As Long, y As Long

    rw = 1: cl = 3 'Apply starting row & column

    Set rng = Range(Cells(rw, cl), Cells(Rows.Count, cl).End(xlUp))

    For Each c In rng
        If c.Value >= i Then
            i = c.Value
        End If
    Next c

    y = 9 'Apply column number for output
    x = Cells(Rows.Count, y).End(xlUp).Offset(1).Row 'Finds the first empty row in that column

    For Each c In rng
        If c = i Then
            Cells(x, y).Resize(, 3).Value = c.Offset(, -2).Resize(, 3).Value
            x = x + 1
        End If
    Next c
End Sub

推荐阅读