Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jo Jo is offline
external usenet poster
 
Posts: 113
Default Move multiple worksheets to a new workbook

Good day,
I am using a macro to create new worksheets in a wkb and consequently all
these "new" worksheets move to a new workbook.
Tried to help me out with a macro recorder:
Sheets(Array("Sheet1 (2)", "Sheet1 (3)")).Move

the line works just exact the way I need, but I'm not able to rephrase it
with variable names of worksheets (in my macro I need to move all worksheets
with item number 5).
Is there any easy solution for this?
Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Move multiple worksheets to a new workbook

Hi Jo,

Try this. It moves only those sheets with an item number greater than 5

Sub Macro1()

Dim wbFrom As Workbook
Dim wbTo As Workbook
Dim ws As Worksheet
Dim i As Single

'Ensure that new workbook is open
'Otherwise goto workbook open routine
On Error GoTo OpenWB
Windows("To WorkBook.xls").Activate
On Error GoTo 0

Set wbFrom = ThisWorkbook
Set wbTo = Workbooks("To WorkBook")

With wbFrom
For Each ws In .Worksheets
If ws.Index 5 Then
ws.Move Befo=wbTo.Sheets(1)
End If
Next ws
End With

GoTo PastOpenWB 'When get to here skip OpenWB

OpenWB:
Workbooks.Open Filename:= _
"C:\Users\Whoever\Documents\Excel\To WorkBook.xls"
Resume Next

PastOpenWB:

End Sub

Regards,

OssieMac


"jo" wrote:

Good day,
I am using a macro to create new worksheets in a wkb and consequently all
these "new" worksheets move to a new workbook.
Tried to help me out with a macro recorder:
Sheets(Array("Sheet1 (2)", "Sheet1 (3)")).Move

the line works just exact the way I need, but I'm not able to rephrase it
with variable names of worksheets (in my macro I need to move all worksheets
with item number 5).
Is there any easy solution for this?
Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
Jo Jo is offline
external usenet poster
 
Posts: 113
Default Move multiple worksheets to a new workbook

Hi OssieMac,
thanks a lot. Probably I will use your advice. But to be completely honest I
was looking for some slim solution.
It quite irritates me that the dumb macro recorder managed it in one
line...;-)
Regards
Jo

"OssieMac" wrote:

Hi Jo,

Try this. It moves only those sheets with an item number greater than 5

Sub Macro1()

Dim wbFrom As Workbook
Dim wbTo As Workbook
Dim ws As Worksheet
Dim i As Single

'Ensure that new workbook is open
'Otherwise goto workbook open routine
On Error GoTo OpenWB
Windows("To WorkBook.xls").Activate
On Error GoTo 0

Set wbFrom = ThisWorkbook
Set wbTo = Workbooks("To WorkBook")

With wbFrom
For Each ws In .Worksheets
If ws.Index 5 Then
ws.Move Befo=wbTo.Sheets(1)
End If
Next ws
End With

GoTo PastOpenWB 'When get to here skip OpenWB

OpenWB:
Workbooks.Open Filename:= _
"C:\Users\Whoever\Documents\Excel\To WorkBook.xls"
Resume Next

PastOpenWB:

End Sub

Regards,

OssieMac


"jo" wrote:

Good day,
I am using a macro to create new worksheets in a wkb and consequently all
these "new" worksheets move to a new workbook.
Tried to help me out with a macro recorder:
Sheets(Array("Sheet1 (2)", "Sheet1 (3)")).Move

the line works just exact the way I need, but I'm not able to rephrase it
with variable names of worksheets (in my macro I need to move all worksheets
with item number 5).
Is there any easy solution for this?
Thanks in advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Move multiple worksheets to a new workbook

sheets("Sheet1 (2)").name = newname1
sheets("Sheet1 (3)").name = newname2

"jo" wrote:

Good day,
I am using a macro to create new worksheets in a wkb and consequently all
these "new" worksheets move to a new workbook.
Tried to help me out with a macro recorder:
Sheets(Array("Sheet1 (2)", "Sheet1 (3)")).Move

the line works just exact the way I need, but I'm not able to rephrase it
with variable names of worksheets (in my macro I need to move all worksheets
with item number 5).
Is there any easy solution for this?
Thanks in advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
Jo Jo is offline
external usenet poster
 
Posts: 113
Default Move multiple worksheets to a new workbook

sorry, probably missed the point. How can I use your aproach in case I have
indefinite number of sheets with item number 5?
Jo

"Joel" wrote:

sheets("Sheet1 (2)").name = newname1
sheets("Sheet1 (3)").name = newname2

"jo" wrote:

Good day,
I am using a macro to create new worksheets in a wkb and consequently all
these "new" worksheets move to a new workbook.
Tried to help me out with a macro recorder:
Sheets(Array("Sheet1 (2)", "Sheet1 (3)")).Move

the line works just exact the way I need, but I'm not able to rephrase it
with variable names of worksheets (in my macro I need to move all worksheets
with item number 5).
Is there any easy solution for this?
Thanks in advance



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move sorted data from one worksheet to multiple worksheets? Mark Excel Worksheet Functions 1 October 4th 07 09:32 AM
Keyboard shortcuts to move between worksheets within a workbook Waj Excel Worksheet Functions 2 March 20th 07 08:24 PM
Move WorkSheets Within Same WorkBook!! James Cooper Excel Programming 3 June 28th 06 05:02 AM
Move worksheets to a new workbook mrdata[_6_] Excel Programming 9 March 5th 06 09:30 PM
Open & process multiple worksheets then move them to different folder. Prasad Vanka Excel Programming 1 May 18th 04 03:26 PM


All times are GMT +1. The time now is 12:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"