一行中的最大号的列名

不同工作表的列标题

iI在表2中有许多行有数据,而iI想要一行的最大列名(即从列名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 

使用MATCH工作表函数会给你匹配MAX的列:

有一个+1因为你的范围从第二列开始! ;)

 Sub shanaya() Dim j As Integer Dim i As Integer Dim z As Integer Dim x As Integer Dim ColOfMax As Integer Dim RgToSearch As Range 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) Set RgToSearch = Sheet8.Range(Sheet8.Cells(j, 2), Sheet8.Cells(j, z)) ColOfMax = Application.WorksheetFunction.Match(Application.WorksheetFunction.Max(RgToSearch), RgToSearch, 0) + 1 Sheet1.Cells(i, 13) = Sheet8.Cells(1, ColOfMax) End If Next j Next i End Sub