vba help - split data and save workbook

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want to split data into two set and save those two workbook into a thisworkbook.path.
File name - a) Data between 01/01/2020 - 30/05/2020
FileName - b) Data - 01/06/2020 onward...

Criteria to split data are Receipt date between
a) 01/01/2020 - 30/05/2020
b) 01/06/2020 - onwards.

how to achieve this task.


Below is a data

Book29
ABCD
1Receipt Datexxxxxxxxx
201/01/2020xxxxxxxxx
301/02/2020xxxxxxxxx
410/03/2020xxxxxxxxx
515/04/2020xxxxxxxxx
606/07/2020xxxxxxxxx
720/08/2020xxxxxxxxx
806/09/2020xxxxxxxxx
916/07/2020xxxxxxxxx
1002/07/2020xxxxxxxxx
1109/09/2020xxxxxxxxx
Sheet1


Thanks
mg
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi Team,

Below is my attempted code, however filtering is not working.

But task is filter data between two dates,...... if there is a data found save in New workbook.
Needs to generate two output files from Single input files.



VBA Code:
Sub Split_Data()

Dim myFileName As String

Dim wbk As Workbook
Set wbk = Workbooks.Open("D:\Testing sample data\Data.xlsx")

Condition1
Range("a1").CurrentRegion.AutoFilter Field:=1, Criteria1:= _
        ">=01/01/2020", Operator:=xlAnd, Criteria2:="<=30/05/2020"


'If greater than 1
Range("a1").CurrentRegion.SpecialCells(12).Copy
Workbooks.Add
Range("a1").PasteSpecial xlPasteAll
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\Data_Jan_May.xlsx"

'Condition -2
Range("a1").CurrentRegion.AutoFilter Field:=1, Criteria1:= _
        ">=01/06/2020"

'if greater than 1
Range("a1").CurrentRegion.SpecialCells(12).Copy
Workbooks.Add
Range("a1").PasteSpecial xlPasteAll
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\June Onward.xlsx"



End Sub


Thanks
mg
mg
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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