返回列表 上一主題 發帖

[發問] A表每單筆資料去查詢B表 得出多列資料 複製到C表 [0613]成功嚕

回復 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

TOP

        靜思自在 : 有時當思無時苦,好天要積雨來糧。
返回列表 上一主題