Sub AAA()
Dim R1 As Range
Dim R2 As Range
Set R1 = Sheets("SHEET1").Rows(1).Find("指定名称", , , xlWhole)
If R1 Is Nothing Then MsgBox "找不到 指定名称": Exit Sub
Set R2 = Sheets("sheet2").Rows(1).Find("目标", , , xlWhole)
If R2 Is Nothing Then MsgBox "找不到 目标": Exit Sub
Sheets("sheet1").Range(R1.Offset(1), Sheets("sheet1").Cells(Rows.Count, R1.Column).End(3)).Copy R2.Offset(1)
End Sub
也可以不用VBA,用以下公式可以达到你要的效果
在sheet2的“目标"列的第二行单元格输入
=OFFSET(Sheet1!$A$1,ROW(A1),MATCH("指定名称",Sheet1!$1:$1,0)-1)
公式下拉填充
Sub 查找复制()
Dim i%, j%
For i = 1 To UsedRange.Columns.Count
If Not Sheets(1).Rows(1).Cells.Find(Cells(1, i), lookat:=xlWhole) Is Nothing Then
j = Sheets(1).Rows(1).Cells.Find(Cells(1, i), lookat:=xlWhole).Column
Sheets(1).Range(Cells(2, j), Cells(65536, j)).Copy Cells(2, i)
End If
Next i
End Sub
将上面的代码复制进SHEET2中。