- 帖子
- 1180
- 主題
- 204
- 精華
- 0
- 積分
- 1051
- 點名
- 0
- 作業系統
- Mac.OS10.6
- 軟體版本
- Office 2003
- 閱讀權限
- 100
- 性別
- 男
- 註冊時間
- 2010-5-3
- 最後登錄
- 2012-9-19
     
|
回復 1# milkpillow
http://gb.twbts.com/index.php?topic=12801.0
主題: sheet2內容固定,比對sheet1後,將符合的列複製於sheet3
Hsieh版主 Re: sheet2內容固定,比對sheet1後,將符合的列複製於sheet3
« 回覆文章 #9 於: 2010-02-28, 18:07:56 »
程式碼:
Sub nn()
Dim Rng As Range, A As Range, Cell As Range
With Sheet2
Set Rng = .Range(.[A1], .[A65536].End(xlUp))'設置比對的標準區域
End With
With Sheet1
For Each A In .Range(.[D1], .[D65536].End(xlUp))'在sheet1的d欄資料循環
If Not Rng.Find(A, lookat:=xlWhole) Is Nothing Then'如果標準區找到d欄的值
If Cell Is Nothing Then Set Cell = A Else Set Cell = Union(Cell, A)'如果變數Cell是不是物件就將d欄設給Cell否則Cell就會將原來範圍增加一儲存格A
End If
Next
End With
Sheet3.Cells = ""'清空Sheet3內容
Cell.EntireRow.Copy Sheet3.[A1]'把Sheet1符合的列複製到Sheet3的A1
End Sub |
|