How to Copy rows from one sheet to another based on the criteria in the second sheet

dsubash

New Member
Joined
Nov 22, 2024
Messages
8
Office Version
  1. 2019
  2. Prefer Not To Say
Platform
  1. Windows
Dummy.xlsx
ABCDEFG
1Sl. NoLocationDateSalesCollectedDueName of Employee
21Sydney01/11/20245005000SELF
32Ireland01/11/2024243024300SELF
43Japan01/11/20245505500SELF
54Tokyo01/11/20243503500SELF
65Delhi01/11/2024293002930SELF
76Ohio01/11/20245505500SELF
87New Jersey01/11/20245505500SELF
98Bangkok01/11/2024273027300SELF
109Bangalore01/11/20243003000SELF
1110Sydney01/11/20242802800SELF
1211Ireland01/11/20244004000SELF
1312Japan01/11/20242202200SELF
1413Tokyo01/11/2024145014500SELF
1514Delhi01/11/20244004000SELF
1615Ohio01/11/2024184018400SELF
1716Sydney01/11/20241001000SELF
1817Ireland01/11/20243503500SELF
1918Sydney01/11/20241001000SELF
2019Ireland01/11/20242502500SELF
2120Japan01/11/2024185018500SELF
2221Tokyo01/11/2024190000SELF
2322Delhi01/11/20241801800OWN
2423Ohio01/11/20241000100KLM
2524New Jersey01/11/20241000100OWN
2625Bangkok01/11/20241000100OWN
2726Sydney01/11/20241001000KLM
2827Ireland01/11/20241300130KLM
2928Japan01/11/20241200120KLM
3029Tokyo01/11/20242802800KLM
3130Delhi01/11/20244004000SELF
3231Sydney01/11/20243103100KLM
3332Ireland01/11/20243800380QRS
3433Japan01/11/20241200120QRS
3534Tokyo01/11/202440400KLM
3635Delhi01/11/20245505500SELF
3736Ohio01/11/2024217021700SELF
3837New Jersey01/11/20241300130OWN
3938Bangkok01/11/20241300130OWN
4039Bangalore01/11/20241300130OWN
4140Sydney01/11/2024103001030KLM
4241Ireland01/11/20241000100KLM
4342Japan01/11/20243700370KLM
4443Tokyo01/11/20243700370KLM
4544Delhi01/11/202450500SELF
4645Ohio01/11/20241001000VWX
4746New Jersey10/11/20241000100KLM
4847Bangkok10/11/20242500250KLM
4948Bangalore10/11/202480080KLM
5049Sydney10/11/20241001000PQR
Daily Transaction



Dummy.xlsx
ABCDEFGHIJK
1ABC Limited
2Daily Sales Update
3
4Date18/11/2024NameSELF
5
6
7Sl. No.NameLocationDateSalesPaidDue
81SELFDelhi18/11/20241000100
92SELFDelhi18/11/20241000100
103SELFDelhi18/11/202470070
114SELFDelhi18/11/20241000100
125SELFDelhi18/11/20241000100
136SELFDelhi18/11/20242800280
147SELFDelhi18/11/20242300230
158SELFDelhi18/11/20244000400
16
Report
Cells with Data Validation
CellAllowCriteria
F4List=Names



Dear All,

I have a database sheet (Daily Transaction) which contains details like name, date, location, sales, collections, dues etc for a specific month.

I need to copy all rows from the master sheet to another sheet (Report) with Name and Date as Criteria to be entered in the report sheet.

Attached is the sample file for reference. When the name and date is changed in the report sheet, i need all rows containing specific name and date to be copied in the report sheet.

Any Formula or VB would be of great help. I am using Office Professional 2019.

Thanks in advance.
Subash D
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Set up your report sheet like the pciture below(the headers and the criteriafields in K1:L2). When you did that, you can use this oneliner in VBA

VBA Code:
Sub jec()
Sheet1.Cells(1).CurrentRegion.AdvancedFilter 2, Sheet2.Range("K1:L2"), Sheet2.Range("A1:G1")
End Sub


1732284398922.png
 
Upvote 0
Set up your report sheet like the pciture below(the headers and the criteriafields in K1:L2). When you did that, you can use this oneliner in VBA

VBA Code:
Sub jec()
Sheet1.Cells(1).CurrentRegion.AdvancedFilter 2, Sheet2.Range("K1:L2"), Sheet2.Range("A1:G1")
End Sub


View attachment 119548
Thanks JEC,

It works as expected. I have placed an shortcut for filtering. I also need an option to clear the filter by way of an shortcut. any possibilities in including the clear filter option in your code.
 
Upvote 0
Put this behind a button

VBA Code:
sheet2.cells(1).currentregion.offset(1).clearcontents
 
Upvote 0
Thanks a Lot J.

I also want to know whether only specific columns can be reproduced in the reports page.

Actually my original sheet contains more than 50 columns, but i need to reproduce only specific columns that match the column header in the reports page. Is it possible?
I am currently hiding the columns that are unnecessary for my reports.
 
Upvote 0
Type your needed headers only. Then change the location in the advanced filter line to that range. Thats about it
 
Upvote 0
Type your needed headers only. Then change the location in the advanced filter line to that range. Thats about it
Sorry J,

I am not exposed to coding.

For example, in my sample sheet, I need only the Location, Sales and collected to be reproduced in the reports page for the same Date and Name Criteria. How should i do the coding?
 
Upvote 0
Ok so type these headernames in a1:c1 (exact same names as in the source sheet)

Then use the code like. Spot the difference with the first code

VBA Code:
Sub jec()
Sheet1.Cells(1).CurrentRegion.AdvancedFilter 2, Sheet2.Range("K1:L2"), Sheet2.Range("A1:C1")
End Sub
 
Upvote 0
Thanks JEC,

It works as expected. I have placed an shortcut for filtering. I also need an option to clear the filter by way of an shortcut. any possibilities in including the clear filter option in your code.
Hi JEC,

I have been using your code successfully. Thanks.
I need the same report for a period of time, say from 01/11/2024 to 10/11/2024 or any other specific date range.
Can you suggest a code to derive at the report for a specific period. I can use Column K for From date and Column L for To Date.
 
Upvote 0
Hi JEC,

I have been using your code successfully. Thanks.
I need the same report for a period of time, say from 01/11/2024 to 10/11/2024 or any other specific date range.
Can you suggest a code to derive at the report for a specific period. I can use Column K for From date and Column L for To Date.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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