LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Copying formulas, formats, and sheet names across workbooks

Hi,

I am trying to copy formulas and formats from one workbook (source) to
another workbook (target). I discovered that the source book doesn't have
its sheets in numerical order and some are missing. In other words, you
might have Sheet1("FirstSheet"), Sheet4("SecondSheet"),
Sheet3("ThirdSheet"), [Sheet2 doesn't exist.] and so on.

I believe I need to work with the names instead of sheet numbers.

To get myself started, I recorded the following macro:

Sub Macro1()
'
Windows("SourceBook.xls").Activate
Sheets("SourceSheet").Select
Cells.Select
Range("A3").Activate
Selection.Copy
Windows("TargetBook.xls").Activate
Cells.Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A1").Select
End Sub

From that, I created the following macro:

Public Sub CopyContentsFormat(lMin As Long, lMax As Long)
Dim index As Long
For index = lMin To lMax
'\This line below doesn't work - see explanation
Windows("SourceBook.xls").Worksheets(index).Cells. Copy
Windows("SourceBook.xls").Worksheets("Sheet" & index).Cells.Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A1").Select
'\How do I copy/transfer the sheet names from the source book to the
'\ target book?
Next index
End Sub

I get the following error for the line that does not work:

Run-Time Error '438'
Object doesn't support this property or method.

When it didn't work, the index was 2, which was lmin. Sheet2 does exist.
So I am not sure what went wrong. But as mentioned above, I think I need to
work with the sheet names anyway, because of missing Sheet numbers and the
sheet order. I think I need to read the sheetnames into an array, and then
work with the sheet names?

Also, I would like to transfer the sheet names from the source book to the
target book. Any help is most appreciated.

Best regards,
Kevin


 
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
Copying Workbooks and keeping the formulas only? John Excel Discussion (Misc queries) 3 September 12th 08 08:45 PM
Copying formulas between workbooks Zoomnbyu Excel Discussion (Misc queries) 0 March 19th 08 07:34 PM
Copying and using formulas including worksheet names Isissoft Excel Discussion (Misc queries) 3 May 5th 07 10:12 PM
Copying Formats between workbooks and worksheets geoff_francis_cox Excel Discussion (Misc queries) 3 July 3rd 05 11:22 PM
Copying Abolute formulas and conditional formats Jerry Foley Excel Worksheet Functions 3 February 14th 05 06:02 PM


All times are GMT +1. The time now is 12:22 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"