Split excel spreadsheet into separate files based on date columnExcel - Change cell colour based on a date in...
What does it take to become a wilderness skills guide as a business?
Is there a logarithm base for which the logarithm becomes an identity function?
Too soon for a plot twist?
Did Amazon pay $0 in taxes last year?
How does learning spells work when leveling a multiclass character?
Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?
Unfamiliar notation in Diabelli's "Duet in D" for piano
Insult for someone who "doesn't know anything"
How can I have x-axis ticks that show ticks scaled in powers of ten?
What is the oldest European royal house?
School performs periodic password audits. Is my password compromised?
PTIJ: Sport in the Torah
Does an unused member variable take up memory?
What is Tony Stark injecting into himself in Iron Man 3?
Was this cameo in Captain Marvel computer generated?
Has a sovereign Communist government ever run, and conceded loss, on a fair election?
I am the person who abides by rules but breaks the rules . Who am I
Why restrict private health insurance?
3.5% Interest Student Loan or use all of my savings on Tuition?
How to install "rounded" brake pads
Can multiple states demand income tax from an LLC?
Why would /etc/passwd be used every time someone executes `ls -l` command?
Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?
Should I file my taxes? No income, unemployed, but paid 2k in student loan interest
Split excel spreadsheet into separate files based on date column
Excel - Change cell colour based on a date in the comment or mixed in with textHow can I split Excel data from one row into multiple rowsCan I split a spreadsheet into multiple files based on a Row in Excel 2013?Remove duplicate rows, and keep newest row based on date columnHow do I split a single row into multiple rows based on quantity in Excel?Split cell data into multiple cellsHow to create text files from excel per column value?How to split multiple worksheets of data by column value and output to separate files?Transpose Stacked Data in One Column to Rows based on Variable Criteria and Unique IdentifiersExcel - Change cell colour based on a date
I have an Excel with a lot of rows 20.000+ that I want to split based on the creation date (date only without time) and save as separate files.
The file looks like:
Can anyone help me with this. I have tried changing some VBA codes I found on this site but ran against errors that I couldn't solve.
microsoft-excel vba
New contributor
add a comment |
I have an Excel with a lot of rows 20.000+ that I want to split based on the creation date (date only without time) and save as separate files.
The file looks like:
Can anyone help me with this. I have tried changing some VBA codes I found on this site but ran against errors that I couldn't solve.
microsoft-excel vba
New contributor
6
Please share the VBA code that didn't work for you and the error you received.
– Worthwelle
10 hours ago
Is there a reason you're looking at VBA rather than filtering by date, then copy/cut and pasting the relevant data to another sheet?
– Alex M
8 hours ago
add a comment |
I have an Excel with a lot of rows 20.000+ that I want to split based on the creation date (date only without time) and save as separate files.
The file looks like:
Can anyone help me with this. I have tried changing some VBA codes I found on this site but ran against errors that I couldn't solve.
microsoft-excel vba
New contributor
I have an Excel with a lot of rows 20.000+ that I want to split based on the creation date (date only without time) and save as separate files.
The file looks like:
Can anyone help me with this. I have tried changing some VBA codes I found on this site but ran against errors that I couldn't solve.
microsoft-excel vba
microsoft-excel vba
New contributor
New contributor
edited 10 hours ago
Worthwelle
2,80331325
2,80331325
New contributor
asked 10 hours ago
user1005845user1005845
6
6
New contributor
New contributor
6
Please share the VBA code that didn't work for you and the error you received.
– Worthwelle
10 hours ago
Is there a reason you're looking at VBA rather than filtering by date, then copy/cut and pasting the relevant data to another sheet?
– Alex M
8 hours ago
add a comment |
6
Please share the VBA code that didn't work for you and the error you received.
– Worthwelle
10 hours ago
Is there a reason you're looking at VBA rather than filtering by date, then copy/cut and pasting the relevant data to another sheet?
– Alex M
8 hours ago
6
6
Please share the VBA code that didn't work for you and the error you received.
– Worthwelle
10 hours ago
Please share the VBA code that didn't work for you and the error you received.
– Worthwelle
10 hours ago
Is there a reason you're looking at VBA rather than filtering by date, then copy/cut and pasting the relevant data to another sheet?
– Alex M
8 hours ago
Is there a reason you're looking at VBA rather than filtering by date, then copy/cut and pasting the relevant data to another sheet?
– Alex M
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Thanks to Shirley Zhang.
Original from: (datanumen.com/blogs/2-fast-means-to-split-an-excel-worksheets-contents-into-multiple-workbooks-based-on-a-specific-column) edited by me.
Due to create, edit and save workbooks, it takes a long time to calculate 20.000+ lines. Maybe more than 15 minutes.
Sub SplitSheetDataIntoMultipleWorkbooksBasedOnSpecificColumn()
Dim objWorksheet As Excel.Worksheet
Dim nLastRow, nRow, nNextRow As Integer
Dim strColumnValue As String
Dim objDictionary As Object
Dim varColumnValues As Variant
Dim varColumnValue As Variant
Dim objExcelWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim aCol As String
aCol = "G" '<- Change Source-Column here
On Error GoTo err1
'Speed up a little bit
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set objWorksheet = ActiveSheet
nLastRow = objWorksheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row
Set objDictionary = CreateObject("Scripting.Dictionary")
For nRow = 2 To nLastRow
'Get the specific Column
'Here my instance is "B" column
'You can change it to your case
'strColumnValue = objWorksheet.Range("B" & nRow).Value
strColumnValue = Format(objWorksheet.Range(aCol & nRow).Value, "mm_dd_yyyy") '<- Set the filter and filename
If objDictionary.Exists(strColumnValue) = False Then
objDictionary.Add strColumnValue, 1
End If
Next
varColumnValues = objDictionary.Keys
For i = LBound(varColumnValues) To UBound(varColumnValues)
varColumnValue = varColumnValues(i)
'Create a new Excel workbook
Set objExcelWorkbook = Excel.Application.Workbooks.Add
Set objSheet = objExcelWorkbook.Sheets(1)
objSheet.Name = objWorksheet.Name
objWorksheet.Rows(1).EntireRow.Copy
objSheet.Activate
objSheet.Range("A1").Select
objSheet.Paste
For nRow = 2 To nLastRow
If CStr(objWorksheet.Range(aCol & nRow).Value) = CStr(varColumnValue) Then
'Copy data with the same column "B" value to new workbook
objWorksheet.Rows(nRow).EntireRow.Copy
nNextRow = objSheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row + 1
objSheet.Range("A" & nNextRow).Select
objSheet.Paste
objSheet.Columns("A:I").AutoFit
End If
Next
objExcelWorkbook.SaveAs (CStr(varColumnValue))
Next
err1:
'Restore slow but necessary settings
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
user1005845 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1412456%2fsplit-excel-spreadsheet-into-separate-files-based-on-date-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks to Shirley Zhang.
Original from: (datanumen.com/blogs/2-fast-means-to-split-an-excel-worksheets-contents-into-multiple-workbooks-based-on-a-specific-column) edited by me.
Due to create, edit and save workbooks, it takes a long time to calculate 20.000+ lines. Maybe more than 15 minutes.
Sub SplitSheetDataIntoMultipleWorkbooksBasedOnSpecificColumn()
Dim objWorksheet As Excel.Worksheet
Dim nLastRow, nRow, nNextRow As Integer
Dim strColumnValue As String
Dim objDictionary As Object
Dim varColumnValues As Variant
Dim varColumnValue As Variant
Dim objExcelWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim aCol As String
aCol = "G" '<- Change Source-Column here
On Error GoTo err1
'Speed up a little bit
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set objWorksheet = ActiveSheet
nLastRow = objWorksheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row
Set objDictionary = CreateObject("Scripting.Dictionary")
For nRow = 2 To nLastRow
'Get the specific Column
'Here my instance is "B" column
'You can change it to your case
'strColumnValue = objWorksheet.Range("B" & nRow).Value
strColumnValue = Format(objWorksheet.Range(aCol & nRow).Value, "mm_dd_yyyy") '<- Set the filter and filename
If objDictionary.Exists(strColumnValue) = False Then
objDictionary.Add strColumnValue, 1
End If
Next
varColumnValues = objDictionary.Keys
For i = LBound(varColumnValues) To UBound(varColumnValues)
varColumnValue = varColumnValues(i)
'Create a new Excel workbook
Set objExcelWorkbook = Excel.Application.Workbooks.Add
Set objSheet = objExcelWorkbook.Sheets(1)
objSheet.Name = objWorksheet.Name
objWorksheet.Rows(1).EntireRow.Copy
objSheet.Activate
objSheet.Range("A1").Select
objSheet.Paste
For nRow = 2 To nLastRow
If CStr(objWorksheet.Range(aCol & nRow).Value) = CStr(varColumnValue) Then
'Copy data with the same column "B" value to new workbook
objWorksheet.Rows(nRow).EntireRow.Copy
nNextRow = objSheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row + 1
objSheet.Range("A" & nNextRow).Select
objSheet.Paste
objSheet.Columns("A:I").AutoFit
End If
Next
objExcelWorkbook.SaveAs (CStr(varColumnValue))
Next
err1:
'Restore slow but necessary settings
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
add a comment |
Thanks to Shirley Zhang.
Original from: (datanumen.com/blogs/2-fast-means-to-split-an-excel-worksheets-contents-into-multiple-workbooks-based-on-a-specific-column) edited by me.
Due to create, edit and save workbooks, it takes a long time to calculate 20.000+ lines. Maybe more than 15 minutes.
Sub SplitSheetDataIntoMultipleWorkbooksBasedOnSpecificColumn()
Dim objWorksheet As Excel.Worksheet
Dim nLastRow, nRow, nNextRow As Integer
Dim strColumnValue As String
Dim objDictionary As Object
Dim varColumnValues As Variant
Dim varColumnValue As Variant
Dim objExcelWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim aCol As String
aCol = "G" '<- Change Source-Column here
On Error GoTo err1
'Speed up a little bit
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set objWorksheet = ActiveSheet
nLastRow = objWorksheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row
Set objDictionary = CreateObject("Scripting.Dictionary")
For nRow = 2 To nLastRow
'Get the specific Column
'Here my instance is "B" column
'You can change it to your case
'strColumnValue = objWorksheet.Range("B" & nRow).Value
strColumnValue = Format(objWorksheet.Range(aCol & nRow).Value, "mm_dd_yyyy") '<- Set the filter and filename
If objDictionary.Exists(strColumnValue) = False Then
objDictionary.Add strColumnValue, 1
End If
Next
varColumnValues = objDictionary.Keys
For i = LBound(varColumnValues) To UBound(varColumnValues)
varColumnValue = varColumnValues(i)
'Create a new Excel workbook
Set objExcelWorkbook = Excel.Application.Workbooks.Add
Set objSheet = objExcelWorkbook.Sheets(1)
objSheet.Name = objWorksheet.Name
objWorksheet.Rows(1).EntireRow.Copy
objSheet.Activate
objSheet.Range("A1").Select
objSheet.Paste
For nRow = 2 To nLastRow
If CStr(objWorksheet.Range(aCol & nRow).Value) = CStr(varColumnValue) Then
'Copy data with the same column "B" value to new workbook
objWorksheet.Rows(nRow).EntireRow.Copy
nNextRow = objSheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row + 1
objSheet.Range("A" & nNextRow).Select
objSheet.Paste
objSheet.Columns("A:I").AutoFit
End If
Next
objExcelWorkbook.SaveAs (CStr(varColumnValue))
Next
err1:
'Restore slow but necessary settings
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
add a comment |
Thanks to Shirley Zhang.
Original from: (datanumen.com/blogs/2-fast-means-to-split-an-excel-worksheets-contents-into-multiple-workbooks-based-on-a-specific-column) edited by me.
Due to create, edit and save workbooks, it takes a long time to calculate 20.000+ lines. Maybe more than 15 minutes.
Sub SplitSheetDataIntoMultipleWorkbooksBasedOnSpecificColumn()
Dim objWorksheet As Excel.Worksheet
Dim nLastRow, nRow, nNextRow As Integer
Dim strColumnValue As String
Dim objDictionary As Object
Dim varColumnValues As Variant
Dim varColumnValue As Variant
Dim objExcelWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim aCol As String
aCol = "G" '<- Change Source-Column here
On Error GoTo err1
'Speed up a little bit
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set objWorksheet = ActiveSheet
nLastRow = objWorksheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row
Set objDictionary = CreateObject("Scripting.Dictionary")
For nRow = 2 To nLastRow
'Get the specific Column
'Here my instance is "B" column
'You can change it to your case
'strColumnValue = objWorksheet.Range("B" & nRow).Value
strColumnValue = Format(objWorksheet.Range(aCol & nRow).Value, "mm_dd_yyyy") '<- Set the filter and filename
If objDictionary.Exists(strColumnValue) = False Then
objDictionary.Add strColumnValue, 1
End If
Next
varColumnValues = objDictionary.Keys
For i = LBound(varColumnValues) To UBound(varColumnValues)
varColumnValue = varColumnValues(i)
'Create a new Excel workbook
Set objExcelWorkbook = Excel.Application.Workbooks.Add
Set objSheet = objExcelWorkbook.Sheets(1)
objSheet.Name = objWorksheet.Name
objWorksheet.Rows(1).EntireRow.Copy
objSheet.Activate
objSheet.Range("A1").Select
objSheet.Paste
For nRow = 2 To nLastRow
If CStr(objWorksheet.Range(aCol & nRow).Value) = CStr(varColumnValue) Then
'Copy data with the same column "B" value to new workbook
objWorksheet.Rows(nRow).EntireRow.Copy
nNextRow = objSheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row + 1
objSheet.Range("A" & nNextRow).Select
objSheet.Paste
objSheet.Columns("A:I").AutoFit
End If
Next
objExcelWorkbook.SaveAs (CStr(varColumnValue))
Next
err1:
'Restore slow but necessary settings
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
Thanks to Shirley Zhang.
Original from: (datanumen.com/blogs/2-fast-means-to-split-an-excel-worksheets-contents-into-multiple-workbooks-based-on-a-specific-column) edited by me.
Due to create, edit and save workbooks, it takes a long time to calculate 20.000+ lines. Maybe more than 15 minutes.
Sub SplitSheetDataIntoMultipleWorkbooksBasedOnSpecificColumn()
Dim objWorksheet As Excel.Worksheet
Dim nLastRow, nRow, nNextRow As Integer
Dim strColumnValue As String
Dim objDictionary As Object
Dim varColumnValues As Variant
Dim varColumnValue As Variant
Dim objExcelWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim aCol As String
aCol = "G" '<- Change Source-Column here
On Error GoTo err1
'Speed up a little bit
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set objWorksheet = ActiveSheet
nLastRow = objWorksheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row
Set objDictionary = CreateObject("Scripting.Dictionary")
For nRow = 2 To nLastRow
'Get the specific Column
'Here my instance is "B" column
'You can change it to your case
'strColumnValue = objWorksheet.Range("B" & nRow).Value
strColumnValue = Format(objWorksheet.Range(aCol & nRow).Value, "mm_dd_yyyy") '<- Set the filter and filename
If objDictionary.Exists(strColumnValue) = False Then
objDictionary.Add strColumnValue, 1
End If
Next
varColumnValues = objDictionary.Keys
For i = LBound(varColumnValues) To UBound(varColumnValues)
varColumnValue = varColumnValues(i)
'Create a new Excel workbook
Set objExcelWorkbook = Excel.Application.Workbooks.Add
Set objSheet = objExcelWorkbook.Sheets(1)
objSheet.Name = objWorksheet.Name
objWorksheet.Rows(1).EntireRow.Copy
objSheet.Activate
objSheet.Range("A1").Select
objSheet.Paste
For nRow = 2 To nLastRow
If CStr(objWorksheet.Range(aCol & nRow).Value) = CStr(varColumnValue) Then
'Copy data with the same column "B" value to new workbook
objWorksheet.Rows(nRow).EntireRow.Copy
nNextRow = objSheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row + 1
objSheet.Range("A" & nNextRow).Select
objSheet.Paste
objSheet.Columns("A:I").AutoFit
End If
Next
objExcelWorkbook.SaveAs (CStr(varColumnValue))
Next
err1:
'Restore slow but necessary settings
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
edited 1 hour ago
answered 1 hour ago
busybytebusybyte
474
474
add a comment |
add a comment |
user1005845 is a new contributor. Be nice, and check out our Code of Conduct.
user1005845 is a new contributor. Be nice, and check out our Code of Conduct.
user1005845 is a new contributor. Be nice, and check out our Code of Conduct.
user1005845 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1412456%2fsplit-excel-spreadsheet-into-separate-files-based-on-date-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
Please share the VBA code that didn't work for you and the error you received.
– Worthwelle
10 hours ago
Is there a reason you're looking at VBA rather than filtering by date, then copy/cut and pasting the relevant data to another sheet?
– Alex M
8 hours ago