標題:
請教版主及各位大大們,如何使用autofilter 連同照片也copy至目的地
[打印本頁]
作者:
cmo140497
時間:
2013-5-3 18:02
標題:
請教版主及各位大大們,如何使用autofilter 連同照片也copy至目的地
Dear 各位版主及大大們您好 :
小弟有一問題,如何使用autofilter or advancedfilter 在於特定條件篩選後作複制的動作,連同欄位大小及儲存格內之照片
已設定圖片屬性為大小位置隨儲存格改變,也有使用pastesAll,也均不得其解,再麻煩各位可以解決小弟的疑惑,感恩!
[attach]14881[/attach]
Sub test()
Dim mytbl As Range
[a1].CurrentRegion.ClearContents
Set mytbl = [a1].End(xlToRight).CurrentRegion
Set myQry = [a1]
mytbl.Columns(4).AdvancedFilter xlFilterCopy, copytorange:=myQry, unique:=True
Set myQry = myQry.CurrentRegion
For i = 2 To myQry.Rows.Count
x = [aa2].End(xlToLeft).Column + 1
With mytbl
.AutoFilter 4, myQry.Rows(i)
.Copy
Cells(1, x).PasteSpecial xlPasteColumnWidths
Cells(1, x).PasteSpecial xlPasteAll
mytbl.AutoFilter
End With
Next
End Sub
複製代碼
[attach]14880[/attach]
作者:
Hsieh
時間:
2013-5-3 19:49
回復
1#
cmo140497
Sub ex()
Set dic = CreateObject("Scripting.Dictionary")
Dim MyQtb As Range, VRng As Range
Set MyQtb = Range("A1").End(xlToRight).CurrentRegion
Application.ScreenUpdating = False
For Each pic In ActiveSheet.Pictures
Set a = pic.TopLeftCell.Offset(, 1)
m = a & a.Offset(, 1)
Set dic(a & a.Offset(, 1)) = Pictures(pic.Name)
Next
For Each a In Range([A2], [A2].End(xlDown))
With MyQtb
.AutoFilter 4, a
Set Rng = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
Set VRng = .SpecialCells(xlCellTypeVisible)
VRng.Copy
Rng.PasteSpecial xlPasteColumnWidths
Rng.PasteSpecial Paste:=xlPasteValues
.AutoFilter
r = 1
Do Until r > Rng.Offset(, 1).End(xlDown).Row - 1
Set c = Rng.Offset(r, 0)
dic(c.Offset(, 1) & c.Offset(, 2)).Copy
c.Select
ActiveSheet.Paste
r = r + 1
Loop
End With
Next
Application.ScreenUpdating = True
End Sub
複製代碼
作者:
cmo140497
時間:
2013-5-6 08:22
回復
2#
Hsieh
Dear 版主您早 :
有一小問題,不知這巨集是哪裡出錯,再麻煩您解決小弟的疑惑,感恩!
[attach]14898[/attach]
作者:
cmo140497
時間:
2013-5-6 08:36
回復
2#
Hsieh
不好意思,小弟沒有解釋的很清楚,小弟用I欄位作為篩選條件,先篩選出不重複之no.值於A欄位,再將A欄位依序當Criteria,再篩選將相同之no.連同圖片,一起複製相鄰之空白欄位
再麻煩版主解決小弟的疑惑,謝謝您!
[attach]14899[/attach]
作者:
cmo140497
時間:
2013-5-6 08:49
回復
3#
cmo140497
歹勢,找到問題了,A欄位,版主以為CRITERIA是原有的,小弟加了進去,另外Pictures,小弟改成ActiveSheet.Pictures(pic.Name)
,就可以了,不好意思,感謝版主的指導
作者:
GBKEE
時間:
2013-5-6 10:49
回復
5#
cmo140497
直接複製
Option Explicit
Sub Ex()
Dim mytbl As Range, myQry As Range, P As Pictures, I As Integer
Application.ScreenUpdating = False
With Sheets("工作表1")
.Activate
.[a1].CurrentRegion.ClearContents
.Range("J1", .[J1].End(xlToRight)).EntireColumn.Clear '清除舊有資料 (Clear 無法刪除圖片)
Set P = .Pictures '圖片集合
For I = P.Count To 1 Step -1
If Intersect(.Range(P(I).TopLeftCell.Address), .[F:F]) Is Nothing Then '圖片位置不在 F欄
P(I).Delete '圖片 刪除
End If
Next
Set mytbl = .[F:I]
Set myQry = .[a1]
mytbl.Columns(4).AdvancedFilter xlFilterCopy, copytorange:=myQry, unique:=True
Set myQry = myQry.CurrentRegion
For I = 2 To myQry.Rows.Count
With mytbl
.AutoFilter 4, myQry.Rows(I)
.SpecialCells(xlCellTypeVisible).Copy
.Parent.Cells(1, .Parent.Columns.Count).End(xlToLeft).Offset(, 1).Select
.Parent.Paste
'ActiveSheet.Paste
End With
Next
End With
mytbl.AutoFilter
myQry.Select
Application.ScreenUpdating = True
End Sub
複製代碼
作者:
cmo140497
時間:
2013-5-6 15:25
回復
6#
GBKEE
感謝版主的指導,小弟又學了新的方法,感恩!
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)