Microsoft Knowledge Base |
|
XL: Error Using a Macro to Copy Data from Grouped Sheets |
|
|
Last reviewed: July 9, 1997
Article ID: Q161206 |
|
The information in this article applies to:
SYMPTOMSWhen you run a Visual Basic for Application macro that copies data from multiple selected worksheets to a single worksheet in another workbook, the following error message may appear:
Run-time error '1004': Copy and paste areas are different shapes.and the macro halts.
CAUSEThis problem occurs when the following conditions are true:
WORKAROUNDMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft Product Support Services (PSS) Engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. To work around this behavior, ungroup the sheets before you run the macro, but preserve the range you want to copy and the sheets that are selected. The following example copies the selected range from sheets that are selected in the source workbook and pastes the information into the first sheet in the specified destination workbook:
MORE INFORMATIONIf the destination workbook contains an equal or greater number of worksheets, the macro copies the data in the specified range from the first sheet in the source workbook to the first sheet in the destination workbook. Note that the macro duplicates the data as many times as the number of sheets you select. The data on the second sheet is placed on the second sheet, and so on. Microsoft Excel groups the sheets. This group starts with the active sheet and includes sheets to the right of the active sheet. If there are not enough sheets to the right of the active sheet in the destination workbook, you receive the error message described in this article.
REFERENCES
Microsoft Excel 97For more information about selecting sheets in a workbook, click the Index tab in Microsoft Excel Help, type the following text
worksheets, selecting sheetsand then double-click the selected text to go to the "Select sheets in a workbook" topic.
Microsoft Excel 5.0 or 7.0For more information about Select Sheets in a Workbook in Microsoft Excel versions 5.0 and 7.0, click Help Topics on the Help menu and type:
sheets, selecting"User's Guide," version 5.0, Chapter 7, "Grouping Worksheets for Fast Data Entry, Editing, and Formatting"
|
|
Additional query words: 97 8.00 7.00 5.00
©1997 Microsoft Corporation. All rights reserved. Legal Notices. |