extract data from sheet to another based on specific date

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
612
Office Version
  1. 2019
Hello
I want extracting data from BRAND sheet to BALANCE sheet based on date=09/02/2023(dd/mm/yyyy) in column A
but should not repeat extracting to the bottom for BALANCE sheet , should clear data for BALANCE sheet before brings data from BRAND sheet.
MM with corrected CBs v03 a (2).xlsm
ABCDEFGH
1DATECODEBRANDTYPEORIGINQTYPRICETOTAL
209/02/2023BSJG580120020BS 1200R20G580JAP200.002,200.00440,000.00
309/02/2023BSTG580120020BS 1200R20G580THI250.002,000.00500,000.00
409/02/2023BSJR187120020BS 1200R20R187JAP300.002,100.00630,000.00
509/02/2023BSTR187120020BS 1200R20R187THI350.002,200.00770,000.00
609/02/2023BSJG580120024BS 1200R24G580JAP400.003,000.001,200,000.00
710/02/2023BSTG582120024BS 1200R24G582THI450.002,800.001,260,000.00
811/02/2023BSJR23070016BS 700R16R230JAP500.00800.00400,000.00
912/02/2023BSJR23075016BS 750R16R230JAP550.00900.00495,000.00
1013/02/2023BSJVSJ75016BS 750R16VSJJAP600.001,300.00780,000.00
1114/02/2023BSJVSJ140020BS 1400R20VSJJAP650.002,000.001,300,000.00
1215/02/2023BSJR180140020BS 1400R20R180JAP700.003,500.002,450,000.00
BRANDS


before

MM with corrected CBs v03 a (2).xlsm
DEFGHIJK
1DATECODEBRANDTYPEORIGINQTYPRICETOTAL
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
BALANCE


after
[
MM with corrected CBs v03 a (2).xlsm
DEFGHIJK
1DATECODEBRANDTYPEORIGINQTYPRICETOTAL
209/02/2023BSJG580120020BS 1200R20G580JAP200.002,200.00440,000.00
309/02/2023BSTG580120020BS 1200R20G580THI250.002,000.00500,000.00
409/02/2023BSJR187120020BS 1200R20R187JAP300.002,100.00630,000.00
509/02/2023BSTR187120020BS 1200R20R187THI350.002,200.00770,000.00
609/02/2023BSJG580120024BS 1200R24G580JAP400.003,000.001,200,000.00
BALANCE
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try:
VBA Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Sheets("BALANCE").UsedRange.Offset(1).ClearContents
    With Sheets("BRANDS")
        .Range("A1").CurrentRegion.AutoFilter 1, "=09-02-2023"
        .AutoFilter.Range.Offset(1).Copy Sheets("BALANCE").Range("A2")
        .Range("A1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
thanks, but it doesn't copy anything .
by the way should past in D2 for BALANCE sheet , not A2
 
Upvote 0
I tested the macro using the data you posted and it worked properly. You just have to change the the A2 to D2. Could you upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
The date format in your file was different from the data your posted. Try:
VBA Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Sheets("BALANCE").UsedRange.Offset(1).ClearContents
    With Sheets("BRANDS")
        .Range("A1").CurrentRegion.AutoFilter 1, "=2023-02-09"
        .AutoFilter.Range.Offset(1).Copy Sheets("BALANCE").Range("A2")
        .Range("A1").AutoFilter
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Here is an alternative solution using Power Query and a Parameter

Load your table to the PQ Editor

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DATE", type date}, {"CODE", type text}, {"BRAND", type text}, {"TYPE", type text}, {"ORIGIN", type text}, {"QTY", Int64.Type}, {"PRICE", Int64.Type}, {"TOTAL", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([DATE] = Table3))
in
    #"Filtered Rows"

Create a second table in Excel as shown in the attached for dates and load it to the PQ Editor

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    Date = #"Changed Type"{0}[Date]
in
    Date

When ever you change the date in the second date table and click on refresh it will update your output table.

Book1
ABCDEFGHIJ
1DATECODEBRANDTYPEORIGINQTYPRICETOTALDate
22/9/2023BSJG580120020BS 1200R20G580JAP20022004400002/9/2023
32/9/2023BSTG580120020BS 1200R20G580THI2502000500000
42/9/2023BSJR187120020BS 1200R20R187JAP3002100630000
52/9/2023BSTR187120020BS 1200R20R187THI3502200770000
62/9/2023BSJG580120024BS 1200R24G580JAP40030001200000
7########BSTG582120024BS 1200R24G582THI45028001260000
8########BSJR23070016BS 700R16R230JAP500800400000
9########BSJR23075016BS 750R16R230JAP550900495000
10########BSJVSJ75016BS 750R16VSJJAP6001300780000
11########BSJVSJ140020BS 1400R20VSJJAP65020001300000
12########BSJR180140020BS 1400R20R180JAP70035002450000
13
14
15
16DATECODEBRANDTYPEORIGINQTYPRICETOTAL
172/9/2023BSJG580120020BS 1200R20G580JAP2002200440000
182/9/2023BSTG580120020BS 1200R20G580THI2502000500000
192/9/2023BSJR187120020BS 1200R20R187JAP3002100630000
202/9/2023BSTR187120020BS 1200R20R187THI3502200770000
212/9/2023BSJG580120024BS 1200R24G580JAP40030001200000
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,166
Members
452,615
Latest member
bogeys2birdies

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