返回列表 上一主題 發帖

請教版主及各位大大們,如何使用autofilter 連同照片也copy至目的地

回復 5# cmo140497
直接複製
  1. Option Explicit
  2. Sub Ex()
  3.     Dim mytbl As Range, myQry As Range, P As Pictures, I As Integer
  4.     Application.ScreenUpdating = False
  5.     With Sheets("工作表1")
  6.         .Activate
  7.         .[a1].CurrentRegion.ClearContents
  8.         .Range("J1", .[J1].End(xlToRight)).EntireColumn.Clear  '清除舊有資料 (Clear 無法刪除圖片)
  9.         Set P = .Pictures                                      '圖片集合
  10.         For I = P.Count To 1 Step -1
  11.             If Intersect(.Range(P(I).TopLeftCell.Address), .[F:F]) Is Nothing Then '圖片位置不在 F欄
  12.                 P(I).Delete                                    '圖片 刪除
  13.             End If
  14.         Next
  15.         Set mytbl = .[F:I]
  16.         Set myQry = .[a1]
  17.         mytbl.Columns(4).AdvancedFilter xlFilterCopy, copytorange:=myQry, unique:=True
  18.         Set myQry = myQry.CurrentRegion
  19.         For I = 2 To myQry.Rows.Count
  20.             With mytbl
  21.                 .AutoFilter 4, myQry.Rows(I)
  22.                 .SpecialCells(xlCellTypeVisible).Copy
  23.                 .Parent.Cells(1, .Parent.Columns.Count).End(xlToLeft).Offset(, 1).Select
  24.                 .Parent.Paste
  25.                 'ActiveSheet.Paste
  26.             End With
  27.         Next
  28.     End With
  29.     mytbl.AutoFilter
  30.     myQry.Select
  31.     Application.ScreenUpdating = True
  32. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 一個缺口的杯子,如果換一個角度看它,它仍然是圓的。
返回列表 上一主題