索引列标题,其中列中的值的最大计数出现

时间:2015-03-25 16:50:51

标签: excel-formula

我有一个包含9列和20行的表。我试图id哪个列标题具有其下面的字段的最大计数,其中值大于或等于指定的数字。表格范围是J4:R23。指定的数字是B6。 J4:R4包含我想要匹配的标题。有关公式的任何想法,以获得适当的列标题?谢谢!

2 个答案:

答案 0 :(得分:0)

这个东西几乎不适合,当然不是最好的解决方案,但应该正常工作:

=IF(SUMIFS($J$5:$J$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$J$4;
IF(SUMIFS($K$5:$K$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$K$4;
IF(SUMIFS($L$5:$L$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$L$4;
IF(SUMIFS($M$5:$M$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$M$4;
IF(SUMIFS($N$5:$N$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$N$4;
IF(SUMIFS($O$5:$O$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$O$4;
IF(SUMIFS($P$5:$P$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$P$4;
IF(SUMIFS($Q$5:$Q$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$Q$4;
IF(SUMIFS($Q$5:$Q$23;">"&$B$6)=MAX(
SUMIFS($J$5:$J$23;">"&$B$6);
SUMIFS($K$5:$K$23;">"&$B$6);
SUMIFS($L$5:$L$23;">"&$B$6);
SUMIFS($M$5:$M$23;">"&$B$6);
SUMIFS($N$5:$N$23;">"&$B$6);
SUMIFS($O$5:$O$23;">"&$B$6);
SUMIFS($P$5:$P$23;">"&$B$6);
SUMIFS($Q$5:$Q$23;">"&$B$6);
SUMIFS($R$5:$R$23;">"&$B$6));$R$4;
"Error in process"
)
)
)
)
)
)
)
)
)

请参阅我的attached file(替换和复制可能已损坏公式)。

答案 1 :(得分:0)

我也做了一个VBA功能,它是多余的等等,但这里是:

Public Function FINDHEADERWHEREMAXCOUNTIFS(Target As Range, Condition As Double)
Dim rng As Range
NumCols = Target.Columns.Count 'counts how many header values we can choose of
Dim Headers() 'defines separate arrays for headers and values (turned out to be obsolete, see variable x)
    ReDim Headers(1 To NumCols)
Dim ValuesArr()
    ReDim ValuesArr(1 To NumCols)

HeaderRow = Target.Row 'row in which headers are located
LastRow = HeaderRow + Target.Rows.Count - 1 'last row with values
FirstColumn = Target.Column 'first column with values
LastColumn = FirstColumn + Target.Columns.Count - 1 'last column with values

For k = FirstColumn To LastColumn 'for each column
    i = i + 1 'set array position
    Headers(i) = Cells(HeaderRow, k).Value2 'set the corresponding header
    For Each rng In Range(Cells(HeaderRow, k), Cells(LastRow, k)) 'for each value
        If rng.Row <> HeaderRow Then 'I mean value, not header
            If rng.Value2 > Condition Then ValuesArr(i) = ValuesArr(i) + 1 'if it's higher than the condition then count
        End If
    Next
Next

x = 1 'default is the first header
For j = 1 To NumCols 'for each header
 If ValuesArr(j) > ValuesArr(x) Then x = j 'if the corresponding value is larger then standard then change the current one to standard
Next
FINDHEADERWHEREMAXCOUNTIFS = Headers(x) 'the standard value's corresponding header is the output
End Function