Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Repeat copy for indifinate number of worksheets


Hi all!

I need some code that will copy a range (incl formatting etc.) of sheet
1, to the exact same range of another workbook's sheet 1. This copy
process must repeat for all worksheets in both workbooks even when some
sheets are deleted or added in the future. I'm not sure if it will work
using the 'For / Next' function. I have attached the example of the code
i have so far. The heavily indented mid section is where I need the
'Repeat copy' code.

Any help would help!



115:


+-------------------------------------------------------------------+
|Filename: Example.txt |
|Download: http://www.thecodecage.com/forumz/attachment.php?attachmentid=115|
+-------------------------------------------------------------------+

--
ARbitOUR
------------------------------------------------------------------------
ARbitOUR's Profile: http://www.thecodecage.com/forumz/member.php?userid=254
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=91316

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Repeat copy for indifinate number of worksheets

Sorry, not a member of that site, so I can't see your attachment and code.
But perhaps this code will get you going. You need to be working with
workbook, worksheet and range objects and it becomes pretty easy and you can
use the
For Each ... Next loop structure to deal with things.

General code looks like this
Sub ExactCopyBetweenBooks()
'copies specified range from each sheet
'in sourceWB to same range in
'a 2nd workbook (destWB)
'on a worksheet with the same name as in sourceWB
Dim destWB As Workbook
Dim destWS As Worksheet
Dim sourceWS As Worksheet
Dim sourceRange As Range

'you need to know the name of the other workbook,
'or code up a way to find what it is
'so you can Set destWB to the other workbook
Set destWB = Workbooks("DestinationWorkbook.xls")
'simple example, copies the same range
'from all worksheets in this workbook
'to sheets with same name in the other workbook
For Each sourceWS In ThisWorkbook.Worksheets
Set sourceRange = sourceWS.Range("A1:Z99")
For Each destWS In destWB.Worksheets
If destWS.Name = sourceWS.Name Then
sourceRange.Copy
destWS.Range("A1").PasteSpecial xlPasteAll
Exit For ' done with this page
End If
Next ' keep looking for sheet name match
Next ' look at next sheet in this workbook
'cleanup and housekeeping
Set sourceRange = Nothing
Set destWB = Nothing
End Sub


"ARbitOUR" wrote:


Hi all!

I need some code that will copy a range (incl formatting etc.) of sheet
1, to the exact same range of another workbook's sheet 1. This copy
process must repeat for all worksheets in both workbooks even when some
sheets are deleted or added in the future. I'm not sure if it will work
using the 'For / Next' function. I have attached the example of the code
i have so far. The heavily indented mid section is where I need the
'Repeat copy' code.

Any help would help!



115:


+-------------------------------------------------------------------+
|Filename: Example.txt |
|Download: http://www.thecodecage.com/forumz/attachment.php?attachmentid=115|
+-------------------------------------------------------------------+

--
ARbitOUR
------------------------------------------------------------------------
ARbitOUR's Profile: http://www.thecodecage.com/forumz/member.php?userid=254
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=91316


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Repeat copy for indifinate number of worksheets


Thanx Latham!

With a bit of tweaking it worked a treat

:)


--
ARbitOUR
------------------------------------------------------------------------
ARbitOUR's Profile: http://www.thecodecage.com/forumz/member.php?userid=254
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=91316

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Repeat copy for indifinate number of worksheets

Thanks for letting us all know that it worked reasonably well, glad I was
able to help a little.

"JLatham" wrote:

Sorry, not a member of that site, so I can't see your attachment and code.
But perhaps this code will get you going. You need to be working with
workbook, worksheet and range objects and it becomes pretty easy and you can
use the
For Each ... Next loop structure to deal with things.

General code looks like this
Sub ExactCopyBetweenBooks()
'copies specified range from each sheet
'in sourceWB to same range in
'a 2nd workbook (destWB)
'on a worksheet with the same name as in sourceWB
Dim destWB As Workbook
Dim destWS As Worksheet
Dim sourceWS As Worksheet
Dim sourceRange As Range

'you need to know the name of the other workbook,
'or code up a way to find what it is
'so you can Set destWB to the other workbook
Set destWB = Workbooks("DestinationWorkbook.xls")
'simple example, copies the same range
'from all worksheets in this workbook
'to sheets with same name in the other workbook
For Each sourceWS In ThisWorkbook.Worksheets
Set sourceRange = sourceWS.Range("A1:Z99")
For Each destWS In destWB.Worksheets
If destWS.Name = sourceWS.Name Then
sourceRange.Copy
destWS.Range("A1").PasteSpecial xlPasteAll
Exit For ' done with this page
End If
Next ' keep looking for sheet name match
Next ' look at next sheet in this workbook
'cleanup and housekeeping
Set sourceRange = Nothing
Set destWB = Nothing
End Sub


"ARbitOUR" wrote:


Hi all!

I need some code that will copy a range (incl formatting etc.) of sheet
1, to the exact same range of another workbook's sheet 1. This copy
process must repeat for all worksheets in both workbooks even when some
sheets are deleted or added in the future. I'm not sure if it will work
using the 'For / Next' function. I have attached the example of the code
i have so far. The heavily indented mid section is where I need the
'Repeat copy' code.

Any help would help!



115:


+-------------------------------------------------------------------+
|Filename: Example.txt |
|Download: http://www.thecodecage.com/forumz/attachment.php?attachmentid=115|
+-------------------------------------------------------------------+

--
ARbitOUR
------------------------------------------------------------------------
ARbitOUR's Profile: http://www.thecodecage.com/forumz/member.php?userid=254
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=91316


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
Indicating Rows to Repeat At Top on all Worksheets Simultaneously Lilbit Excel Worksheet Functions 3 May 27th 08 01:23 PM
Repeat printing rows in multiple worksheets KevinG Excel Discussion (Misc queries) 19 November 27th 07 10:42 PM
How can i repeat certain rows in all worksheets in an excel file reji Excel Discussion (Misc queries) 1 February 12th 07 11:23 AM
How do I set up a column to repeat on other worksheets in Excel danmc1000 Excel Discussion (Misc queries) 2 January 27th 06 03:25 PM
Modify a Macro to Repeat for all Selected Worksheets carl Excel Worksheet Functions 2 January 12th 06 04:56 PM


All times are GMT +1. The time now is 08:28 PM.

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

About Us

"It's about Microsoft Excel"