2017-03-08 71 views
-1

我有很多行在工作表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 

回答

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))) 

第一行發現該行中的最大值。第二行返回列標題(大概在第1行,因爲您從第2行搜索)。