Excel,在找到max时排除重复的细胞?

时间:2015-07-16 17:27:01

标签: excel

我有一系列细胞从B10到B10000,前100个细胞是显着的值,然后接下来的5个细胞是微不足道的,包括时间和系列号。这在剩余的细胞中重复我想找到最大的重要值,不包括重复的无关紧要的5个细胞?

1 个答案:

答案 0 :(得分:0)

试试这个,但它还没有经过测试。它应该只返回最高值。

编辑:测试并运作。

Sub FindMax
    Dim i as integer
    Dim j as integer
    dim k as integer
    Dim MyValues(10000) as long 'Use redim preserve I'm too lazy to look it up
    Dim maxValue as long
     'loop through your values, skip 5 every 100
    j = 0
    For i = 100 to 10000
        if k = 100 Then 
            i = i + 5
            k = 0
         end if

        if not k = 100 Then
            MyValues(j) = [SheetName].Range("B" & i)
            j = j + 1
            k = k + 1
        end if
    Next
    ' You now have an array with only your values you wanna look at
    ' We loop through and find the biggest value in there
    for i = LBound(Myvalues) to UBound(Myvalues)
         if myvalues(i) > MaxValue then MaxValue = myvalues(i)
    next
    msgbox MaxValue
End sub
相关问题