WolfOctober
New Member
- Joined
- Sep 2, 2017
- Messages
- 9
Here's the code:
For i = 5 To 173 Step 7
Sheets("Data Sheet").Select
Columns("D:G").Select
Selection.AutoFilter
Sheets("Data Sheet").Range("D:G").AutoFilter Field:=4, Criteria1:="HBsAg"
Sheets("Data Sheet").Range("D:G").AutoFilter Field:=1, Criteria1:=Sheets("List of Sites").Range("B" & i)
Columns("E:E").Select
Selection.Copy
Worksheets("Data Sheet").AutoFilterMode = False
ActiveSheet.Paste Destination:=Worksheets("Test").Columns((i + 2) / 7)
Sheets("Test").Columns((i + 2) / 7).RemoveDuplicates Columns:=1, Header:=xlNo
Next i
Since I used Macro Recorder, the code includes .Select, .Copy, and .Paste, which I've been told are big no-nos when it comes to macro speed and efficiency. The above code works, but it's very slow...
Can someone help me modify the code such that it does not include these commands?
Thanks!
For i = 5 To 173 Step 7
Sheets("Data Sheet").Select
Columns("D:G").Select
Selection.AutoFilter
Sheets("Data Sheet").Range("D:G").AutoFilter Field:=4, Criteria1:="HBsAg"
Sheets("Data Sheet").Range("D:G").AutoFilter Field:=1, Criteria1:=Sheets("List of Sites").Range("B" & i)
Columns("E:E").Select
Selection.Copy
Worksheets("Data Sheet").AutoFilterMode = False
ActiveSheet.Paste Destination:=Worksheets("Test").Columns((i + 2) / 7)
Sheets("Test").Columns((i + 2) / 7).RemoveDuplicates Columns:=1, Header:=xlNo
Next i
Since I used Macro Recorder, the code includes .Select, .Copy, and .Paste, which I've been told are big no-nos when it comes to macro speed and efficiency. The above code works, but it's very slow...
Can someone help me modify the code such that it does not include these commands?
Thanks!