VBA Advanced filter to x1filtercopy data that matches 3 cells

paublojobino

New Member
Joined
May 27, 2022
Messages
10
Office Version
  1. 2010
Platform
  1. Windows
Hi there,
I want to copy data from a source spreadsheet (sheet1) to another spreadsheet (sheet2) if it matches the three criteria listed below

add to report = Y (column a)
date = is within (user enters in"a1" to "a2")
job code = is equal to "a3"

How can i use VBA and advanced filter?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Arrange your data as follows:
varios 13jun2022.xlsm
ABCD
1datedateadd to reportjob code
2>=44716<=44722YJ7
3Initial Date04-jun
4Final Date10-jun
5add to reportdatejob code
6Y01-junJ5
7Y02-junJ5
8Y03-junJ6
9Y04-junJ7
10N05-junJ5
11N06-junJ5
12N07-junJ6
13Y05-junJ7
14Y09-junJ5
15Y10-junJ7
16N11-junJ6
17N12-junJ7
Hoja5
Cell Formulas
RangeFormula
A2A2=">="&B3
B2B2="<="&B4


Capture the dates in B3 and in B4.
Modify column "C" in the macro by the letter of the last column with data.

VBA Code:
Sub Macro2()
  Dim lr As Long
  With Sheets("Sheet1")
    lr = .Range("A" & Rows.Count).End(3).Row
    .Range("A5:C" & lr).AdvancedFilter xlFilterInPlace, .Range("A1:D2"), False
    .Range("A6:C" & lr).Copy Sheets("Sheet2").Range("A2")
    .ShowAllData
  End With
End Sub

Note: It is important that the names of the columns in A1, B1, C1 and D1 are the same as the names of the headings of your information.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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