Filter 3 columns of data using 1 criteria, and copy to a different workbook

davellc

New Member
Joined
Dec 6, 2018
Messages
7
Hello,

I need to do the following:

Being in Workbook1, activate Workbook2 which contains the data below; filter the data in Columns A to C so that only the "c"'s in column a remain ; copy only the visible data and paste it into Workbook 1.
[TABLE="width: 715"]
<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD="colspan: 10"]The number of rows that need to be filtered will vary from day to day and so will the number of "C" rows post filter.[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]

[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Van Trip[/TD]
[TD]Start[/TD]
[TD]End[/TD]
[TD]Orders[/TD]
[TD]No. Of Orders[/TD]
[TD]Lane[/TD]
[TD]C/Out[/TD]
[TD]Load[/TD]
[TD]Van Reg.[/TD]
[TD]Driver[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]05:00[/TD]
[TD]08:00[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]05:01[/TD]
[TD]08:01[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]05:02[/TD]
[TD]08:02[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]05:03[/TD]
[TD]08:03[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]05:04[/TD]
[TD]08:04[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]05:05[/TD]
[TD]08:05[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]05:06[/TD]
[TD]08:06[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]06:18[/TD]
[TD]10:36[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]06:21[/TD]
[TD]10:37[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]

I have been unable to find a way to select the variable range to begin filtering and then apply the filter.

I have tried solutions from various sites including using DIM and Rng and trying to use that to autofilter (I run into an error with the field bit of "AutoFilter field:=1" "and attempted to modify them but my inexperience seems to be resulting in errors.

Thanks in advance for any help you can supply
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Is this what you mean?

Code:
Sub davellc()
Dim LR As Long
LR = Worksheets("WKBK2").Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("WKBK2").Range("A1:J" & LR).AutoFilter Field:=1, Criteria1:="C"
Worksheets("WKBK2").Range("A1:J" & LR).SpecialCells(xlCellTypeVisible).Copy Sheets("WKBK1").Range("A1")
Worksheets("WKBK2").AutoFilterMode = False
End Sub
 
Upvote 0
Brilliant.

Worked first time and I have used this several times on other sheets already.

Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top