- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 103
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-4-29
               
|
5#
發表於 2012-9-3 14:11
| 只看該作者
回復 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 |
|