migrate data to a new workbook

Addora

New Member
Joined
Jan 4, 2014
Messages
11
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


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]


 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi there,

First of all, please paste your code correctly, it really hard to understand that way.

then I don't exactly understand what you want.

you have sheets with name reflecting the month, and you want to move each sheet to a new worbook ?

rgds.
 
Upvote 0
Hi,

that code that i use paste my sheet to a new one at the same workbook, and use a specific cell as a title for this migrated sheet, this cell contain a date with this format ("dd-mmm-yyyy").
what i want is instead of migrate this sheet to a new one at the same workbook; ask to migrate it to a new workbook. i'll migrate this data daily so that every sheet will titled with a different date, ask if the workbook name use the its sheets title ("mmm-yyyy"). and when starting migrate a new sheets titled with a new month; create a new workbook titled by it's month.
the location of migrated workbook will be at desktop.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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