ericvanlooy
New Member
- Joined
- Dec 1, 2017
- Messages
- 4
Hi,
I would greatly appreciate it if you could help (and teach!) this Newbie to macros with the following issue:
I have a workbook with multiple columns containing consolidated data, of which the content needs to be split up into a number of new workbooks.
The data that needs to be copied/pasted into the new workbooks follows a pattern, which I'm sure can be programmed into a Macro.
For instance:
The first 4 columns are always copied into the new workbooks, but column 5 will be variable:
- New workbook 1 will also contain the values from column E
- New workbook 2 will also contain the values from column H (E+3)
- New workbook 3 will also contain the values from column K (E+6)
- New workbook 4 will also contain the values from column N (E+9)
etc...
The copy/paste macro needs to end when the value in row 1 of the 5th column is called "Source"
For now, I have a very manual Macro (based on a recording), but I have a number of Workbooks (with an unequal amount of columns) I would like to apply this Macro on.
This is what I have to give you an idea:
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook
Application.DisplayAlerts = False
Columns("A:E").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ChDir _
thisWb.Path
ActiveWorkbook.SaveAs Filename:= _
thisWb.Path & "" & _
thisWb.ActiveSheet.Name & "-" & ActiveSheet.Range("E1").Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
thisWb.Activate
Range("A:D,H:H").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ChDir _
thisWb.Path
ActiveWorkbook.SaveAs Filename:= _
thisWb.Path & "" & _
thisWb.ActiveSheet.Name & "-" & ActiveSheet.Range("E1").Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
thisWb.Activate
Range("A:D,K:K").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ChDir _
thisWb.Path
ActiveWorkbook.SaveAs Filename:= _
thisWb.Path & "" & _
thisWb.ActiveSheet.Name & "-" & ActiveSheet.Range("E1").Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
thisWb.Close
Application.DisplayAlerts = True
End Sub
Thanks in advance for your help!
I would greatly appreciate it if you could help (and teach!) this Newbie to macros with the following issue:
I have a workbook with multiple columns containing consolidated data, of which the content needs to be split up into a number of new workbooks.
The data that needs to be copied/pasted into the new workbooks follows a pattern, which I'm sure can be programmed into a Macro.
For instance:
The first 4 columns are always copied into the new workbooks, but column 5 will be variable:
- New workbook 1 will also contain the values from column E
- New workbook 2 will also contain the values from column H (E+3)
- New workbook 3 will also contain the values from column K (E+6)
- New workbook 4 will also contain the values from column N (E+9)
etc...
The copy/paste macro needs to end when the value in row 1 of the 5th column is called "Source"
For now, I have a very manual Macro (based on a recording), but I have a number of Workbooks (with an unequal amount of columns) I would like to apply this Macro on.
This is what I have to give you an idea:
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook
Application.DisplayAlerts = False
Columns("A:E").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ChDir _
thisWb.Path
ActiveWorkbook.SaveAs Filename:= _
thisWb.Path & "" & _
thisWb.ActiveSheet.Name & "-" & ActiveSheet.Range("E1").Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
thisWb.Activate
Range("A:D,H:H").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ChDir _
thisWb.Path
ActiveWorkbook.SaveAs Filename:= _
thisWb.Path & "" & _
thisWb.ActiveSheet.Name & "-" & ActiveSheet.Range("E1").Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
thisWb.Activate
Range("A:D,K:K").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ChDir _
thisWb.Path
ActiveWorkbook.SaveAs Filename:= _
thisWb.Path & "" & _
thisWb.ActiveSheet.Name & "-" & ActiveSheet.Range("E1").Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
thisWb.Close
Application.DisplayAlerts = True
End Sub
Thanks in advance for your help!