我有很多行在表2中有数据,我想要一行最大的列名(即如果循环中从B2的列名到AH2)。
Sub shanaya()
Dim j As Integer
Dim i As Integer
Dim z As Integer
Dim x As Integer
z = 35
For i = 11 To 28
For j = 2 To 19
If Sheet8.Cells(j, 1) = Sheet1.Cells(i, 1) Then
Sheet1.Cells(i, 10) = Sheet8.Cells(j, z)
Max [(Sheet8.Cells(J,2)): (Sheet8.Cells(j,z))]
Sheet1.Cells(i,13) = column header of max function
End If
Next j
Next i
End Sub
答案 0 :(得分:1)
您需要的两个关键行是:
MaxVal = application.max(sheet8.range(sheet8.cells(j,2),sheet8.cells(j,z)))
sheet1.cells(i,13) = sheet8.cells(1,application.match(MaxVal,sheet8.rows(j)))
第一行找到行中的最大值。第二行返回列标题(当您从第2行搜索时,可能在第1行中)。