Hi,
Please i ask for help as i have a sheet that i update daily and with each update an VBA migrate it to a new sheet at the same workbook, this code use a specific cell "contain date eg: 17- Jul-2014" as a title to the new sheet.
i want to migrate this sheets update to a new workbook and its title will be the titled sheet month "Jul-2014". With the first sheet in a new month, want to migrate it to a new workbook titled with its month and contain the month update sheets. want new workbook for each new month
the main sheet that the data will copied from is called "Preview", its copied range will be from ("A1:DA500"), this data wil pasted as "Values and number formats"
this code that i use to migrate the sheet to the same workbook
Please i ask for help as i have a sheet that i update daily and with each update an VBA migrate it to a new sheet at the same workbook, this code use a specific cell "contain date eg: 17- Jul-2014" as a title to the new sheet.
i want to migrate this sheets update to a new workbook and its title will be the titled sheet month "Jul-2014". With the first sheet in a new month, want to migrate it to a new workbook titled with its month and contain the month update sheets. want new workbook for each new month
the main sheet that the data will copied from is called "Preview", its copied range will be from ("A1:DA500"), this data wil pasted as "Values and number formats"
this code that i use to migrate the sheet to the same workbook
Code:
[COLOR=#000088][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#000000][FONT=inherit] CopyNew[/FONT][/COLOR][COLOR=#666600][FONT=inherit]()[/FONT][/COLOR]
[COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#000000][FONT=inherit] wsNew [/FONT][/COLOR][COLOR=#000088][FONT=inherit]As[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Worksheet [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#000000][FONT=inherit] myRange [/FONT][/COLOR][COLOR=#000088][FONT=inherit]As[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Range [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#000000][FONT=inherit] strName [/FONT][/COLOR][COLOR=#000088][FONT=inherit]As[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]String[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Application[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]ScreenUpdating [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]False[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]With[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"preview"[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#880000][FONT=inherit]'Can't use / in sheet names, changed format:[/FONT][/COLOR][COLOR=#000000][FONT=inherit] strName [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Format[/FONT][/COLOR][COLOR=#666600][FONT=inherit](.[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"C2"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Value[/FONT][/COLOR][COLOR=#666600][FONT=inherit],[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#008800][FONT=inherit]"dd-mmm-yyyy"[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Set[/FONT][/COLOR][COLOR=#000000][FONT=inherit] myRange [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"A1:DA500"[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Set[/FONT][/COLOR][COLOR=#000000][FONT=inherit] wsNew [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] ThisWorkbook[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Add[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]After[/FONT][/COLOR][COLOR=#666600][FONT=inherit]:=[/FONT][/COLOR][COLOR=#000000][FONT=inherit]ThisWorkbook[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"preview"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]))[/FONT][/COLOR][COLOR=#000000][FONT=inherit] wsNew[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Name [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] strName myRange[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Copy wsNew[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Cells[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit],[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]PasteSpecial xlPasteValues wsNew[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Cells[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit],[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]PasteSpecial xlPasteFormats wsNew[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Cells[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit],[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]PasteSpecial xlPasteColumnWidths Application[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]CutCopyMode [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]False[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Call[/FONT][/COLOR][COLOR=#000000][FONT=inherit] SortSheets [/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Move Before[/FONT][/COLOR][COLOR=#666600][FONT=inherit]:=[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Sheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#880000][FONT=inherit]'Move the "preview" sheet to the be the first[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]End[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]With[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Application[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]ScreenUpdating [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]True[/FONT][/COLOR][COLOR=#000000][FONT=inherit][/FONT][/COLOR][COLOR=#000088][FONT=inherit]End[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#000000][FONT=inherit][/FONT][/COLOR][COLOR=#000088][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#000000][FONT=inherit] SortSheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]()[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#000000][FONT=inherit] i [/FONT][/COLOR][COLOR=#000088][FONT=inherit]As[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Long[/FONT][/COLOR][COLOR=#666600][FONT=inherit],[/FONT][/COLOR][COLOR=#000000][FONT=inherit] j [/FONT][/COLOR][COLOR=#000088][FONT=inherit]As[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Long[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]For[/FONT][/COLOR][COLOR=#000000][FONT=inherit] i [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]To[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Sheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Count [/FONT][/COLOR][COLOR=#000088][FONT=inherit]For[/FONT][/COLOR][COLOR=#000000][FONT=inherit] j [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]To[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Sheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Count [/FONT][/COLOR][COLOR=#666600][FONT=inherit]-[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]If[/FONT][/COLOR][COLOR=#000000][FONT=inherit] UCase[/FONT][/COLOR][COLOR=#666600][FONT=inherit]$([/FONT][/COLOR][COLOR=#000000][FONT=inherit]Sheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]j[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Name[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]>[/FONT][/COLOR][COLOR=#000000][FONT=inherit] UCase[/FONT][/COLOR][COLOR=#666600][FONT=inherit]$([/FONT][/COLOR][COLOR=#000000][FONT=inherit]Sheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]j [/FONT][/COLOR][COLOR=#666600][FONT=inherit]+[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Name[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Then[/FONT][/COLOR][COLOR=#000000][FONT=inherit] Sheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]j[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Move After[/FONT][/COLOR][COLOR=#666600][FONT=inherit]:=[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Sheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]j [/FONT][/COLOR][COLOR=#666600][FONT=inherit]+[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]End[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]If[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Next[/FONT][/COLOR][COLOR=#000000][FONT=inherit] j [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Next[/FONT][/COLOR][COLOR=#000000][FONT=inherit] i [/FONT][/COLOR]</pre>[COLOR=#000088][FONT=inherit]End[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]Sub[/FONT][/COLOR]