divide sheet into books based on column date

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
672
Office Version
  1. 365
Platform
  1. Windows
hi
i have a master sheet with 4 columns, name, date, amount, type
i want to split into separate workbooks based on column date
each workbook with 1 sheet
workbook named as the split month ex. 7_2022, 8_2022
what would be code to do that?
thanks in advance
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try this Example, copy table below

Range F1 = Link Document

NameDateAmountTypeC:\Users\BJ900265\Documents\
AB
11/11/2023​
10001
AB
12/10/2023​
20002
AC
10/9/2023​
30003
AA
12/11/2023​
40004
AC
12/7/2023​
50005
AA
10/9/2023​
60006
AD
10/9/2023​
70007
AF
11/11/2023​
80008
AH
11/11/2023​
90009
AS
11/11/2023​
100010

1702373101842.png



VBA Code:
Sub CreateLoop()


Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim S1 As Worksheet
Set S1 = ThisWorkbook.Sheets("Sheet2") 'Change With ur Sheet Name

If S1.AutoFilterMode Then S1.AutoFilter.ShowAllData


Dim Nwb, Awb As Workbook
Dim Nsh As Worksheet
Set Awb = ActiveWorkbook


'To Make File Name, u can edit it
Range("F2").Formula = "=TEXTJOIN(""_"",,TEXT(B2,""MM""),TEXT(B2,""YYYY""))"
Range("F2").AutoFill Destination:=Range("F2:F" & Range("B" & Rows.Count).End(xlUp).Row)
Range(Selection, Selection.End(xlDown)).Select


'Loop
Dim i, f As Integer

For i = 2 To Application.CountA(S1.Range("B:B"))


S1.Range("A1:D1").AutoFilter 2, S1.Range("B" & i).Value 'looping by filter


Set Nwb = Workbooks.Add
Set Nsh = Nwb.Sheets(1)


S1.Range("A1:D1" & Cells(Rows.Count, "A").End(xlUp).Row).Copy  'copy data

Nsh.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Nsh.UsedRange.EntireColumn.ColumnWidth = 15

Nwb.SaveAs S1.Range("F1").Value & S1.Range("F" & i).Value & ".xlsx"
Nwb.Close False


Next i


If S1.AutoFilterMode Then S1.AutoFilter.ShowAllData

S1.Range("F2:F" & Cells(Rows.Count, "B").End(xlUp).Row).ClearContents


MsgBox "Done"


End Sub


*If there’s any unclear information please let me know
 
Upvote 0
hi
where do i add that each book the sheet needs to be named Sheet1
each table needs to be named Billing_2
 
Upvote 0
where do i add that each book the sheet needs to be named Sheet1
When adding a new Excel book, each sheet will be named "Sheet1" automatically, right?

each table needs to be named Billing_2
what does it mean by naming it "Table"?
What is meant by "table", I don't understand that, sorry
 
Upvote 0

Forum statistics

Threads
1,215,101
Messages
6,123,096
Members
449,096
Latest member
provoking

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