Copy Paste Filtered Data using simple VBA code (2021)

preview_player
Показать описание
Hi,
In today's video I will show a simple VBA code that can really help with daily routines. If you need to copy data between sheets based on a certain criteria, this video will help. The code will copy data from one sheet to another within the same workbook based on a filtered column set by the user.
It's a very basic code that you can build on and fit to your needs.

Here is the full code:

Sub Copy_Rows()
Dim WS As Worksheet, WD As Worksheet, Filter As Variant
Filter = InputBox("Which Region to copy?")
Set WS = Sheets("Source")
Set WD = Sheets("Destination")
Call filter_and_move_data(WS, WD, 2, Filter)
MsgBox "Data copied"
End Sub

Sub filter_and_move_data(WS As Worksheet, WD As Worksheet, _
col As Integer, Name As Variant)
WD.Cells.Clear
With WS.Range("$A$1:$ZZ$9999")
.AutoFilter field:=col, Criteria1:=Name
End With
WS.Range("A1:ZZ9999").SpecialCells(xlCellTypeVisible).Copy
WD.Range("A1").PasteSpecial Paste:=xlPasteAll
Application.CutCopyMode = False
WS.AutoFilterMode = False
WD.AutoFilterMode = False
End Sub
Рекомендации по теме
Комментарии
Автор

Thanks for this. I like this code but you didn't share the dailogue box when selecting regions for your viewers. We are unsure what it looks like

whitefox