回復 4#tommy.lin
不懂的地方按F1看說明是最好的書籍
Sub ex()
With Sheets("Sheet1")
If Application.CountA(.[B:B]) = 0 Then Exit Sub 'B欄無資料就跳出程序
For Each a In .Range("B:B").SpecialCells(xlCellTypeConstants) '循環每個B欄的資料
With Sheets("Data")
Set c = .Rows(1).Find(a, lookat:=xlWhole) '在Sheets("Data")第一列找尋
k = IIf(Sheets("result").Cells(1, .Columns.Count).End(xlToLeft) = "", 0, 1) '假如要複製的目標位置在Sheets("result")的A欄,位移量為0
Range(c, c.End(xlDown)).Copy Sheets("result").Cells(1, .Columns.Count).End(xlToLeft).Offset(, k) '複製資料
End With
Next
End With
End Sub