簡體   English   中英

如何復制過濾范圍,然后使用 vba 將該過濾范圍粘貼到同一張紙中的另一個過濾范圍

[英]How to copy filtered range and then to paste that filtered range itno another filtered range in the same sheet using vba

我在 excel 中需要此任務的幫助,我有一個大文件,里面有過濾器,首先我需要為 FCDP 21 過濾它,我必須復制該值,然后重復該過濾但為 MSR 21,和在那里粘貼該值,這是我編寫的代碼,但是當它需要粘貼值時它不起作用。

Dim s As Range
Dim visible_source_cells As Range
Dim destination_cells As Range
Dim source_cell As Range
Dim dest_cell As Range
With Range("A2:R667")
        .AutoFilter field:=5, Criteria1:="FCDP 21"
  End With
Set s = Application.Selection
s.SpecialCells(xlCellTypeVisible).Select
Set visible_source_cells = Application.Selection
Set Source = Application.InputBox("Please select the destination cells:", Type:=8)
 With Range("A2:R667")
        .AutoFilter field:=5, Criteria1:="MSR M-1 21"
  End With
Set destination_cells = Application.InputBox("Please select the destination cells:", Type:=8)
For Each source_cell In Source
source_cell.Copy
    For Each dest_cell In destination_cells
If dest_cell.EntireRow.RowHeight <> 0 Then
dest_cell.PasteSpecial
Set destination_cells = dest_cell.Offset(1).Resize(destination_cells.Rows.Count)
Exit For
End If
Next dest_cell
Next source_cell
End Sub```

雖然在 vba 中是可能的,但我建議您使用 powerQuery 來完成此任務。

  1. Select A1 你的源數據
  2. Go 到菜單:數據 > 獲取數據 > 從表格范圍 > select 你的完整表格,如果你有標題,請選中該框。

Excel 將打開“PowerQuery”

  1. 添加過濾器(列名稱旁邊的三角形)
  2. 單擊“關閉並加載到”選擇表 select 您想要過濾表的位置,單擊確定。
  3. 保存您的文件。

每次更新源表(也可以是外部文件)時,只需點擊數據 > 刷新按鈕,過濾后的表就會更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM