Code Visual Basic

[Solved/Closed]
Report
Posts
3
Registration date
Tuesday March 24, 2015
Status
Member
Last seen
March 26, 2015
-
Posts
3
Registration date
Tuesday March 24, 2015
Status
Member
Last seen
March 26, 2015
-
Hello,

I've been unable to copy data from one sheet to another, based on selecting multiple criteria.

I've been able to use the string below to copy rows to sheet 2 by selecting value ("5064") in Column G, sheet 1. I need to select more than one value ("5066, 5067") is also required, this also needs to copied over to sheet 2.

Thank you in advance for your answers.
Regards David ...

Application.ScreenUpdating = False
With Worksheets("Sheet1")
.Columns("G").AutoFilter field:=1, Criteria1:="5064"
.UsedRange.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End With
With Worksheets("Sheet2")
.Columns("G").Cut
.Columns("A").Insert
.Select
End With
Worksheets("Sheet1").AutoFilterMode = False
Application.ScreenUpdating = True

1 reply

Posts
2803
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
September 13, 2021
481
Hi David,

Try replacing the following line:
.Columns("G").AutoFilter field:=1, Criteria1:="5064"

with this one:
.Columns("G").AutoFilter field:=1, Criteria1:=Array("5064", "5066", "5067"), Operator:=xlFilterValues


Best regards,
Trowa
Monday, Tuesday and Thursday are usually the days I'll respond. Bear this in mind when awaiting a reply.
Posts
3
Registration date
Tuesday March 24, 2015
Status
Member
Last seen
March 26, 2015

TrowaD

Your solution worked perfectly, thanks heaps really appreciated your prompt answer

Regards David ....