|
发表于 2018-5-9 14:55
来自手机
|
显示全部楼层
Sub FillByHeader()
Application.ScreenUpdating = False
Dim sht1 As Worksheet, sht As Worksheet
Dim lRow As Long, lCol As Long, lRow1 As Long, lCol1 As Long
Dim cell1 As Range, cell2 As Range
Set sht1 = ActiveWorkbook.Sheets("最终结果")
For Each sht In ActiveWorkbook.Sheets
If sht.Name <> sht1.Name Then
For Each cell1 In sht.Range("A1:E1")
For Each cell2 In sht1.Range("A1:E1")
If cell1.Value = cell2.Value Then
lCol = cell1.Column
lRow = sht.Columns(lCol).Cells(Rows.Count, 1).End(xlUp).Row
lCol1 = cell2.Column
lRow1 = sht1.Columns(lCol1).Cells(Rows.Count, 1).End(xlUp).Row
If lRow > 1 Then
sht.Activate
sht.Range(Cells(2, lCol), Cells(lRow, lCol)).Copy sht1.Cells(lRow1 + 1, lCol1)
End If
End If
Next cell2
Next cell1
End If
Next sht
End Sub |
|