More Data Pasted Than Expected with SELECTION.OFFSET.SELECT (113703)
The information in this article applies to:
- Microsoft Excel for Windows 95 7.0a
- Microsoft Excel for Windows 5.0c
This article was previously published under Q113703 SYMPTOMS
When you use the following Visual Basic, Applications Edition, command in a
macro
SELECTION.OFFSET(rowOffset, columnOffset).SELECT
in conjunction with the Copy and Paste methods, you may receive the
following unexpected results:
- More data is pasted to the destination than expected.
-or-
- You receive the "Copy and Paste Areas Are Different Shapes" error
message.
CAUSE
When you use a macro to paste data in a worksheet, and you then attempt to
paste another selection to the same worksheet, if you do not make a new
selection for the range that you want to paste to, the copied data is
pasted to the range that you previously pasted to. For example, if you copy
one column of cells, and the last range you pasted to contained three
columns, when you use the Paste method without making another selection,
the three columns are filled with the single column of data you copied.
If you use the Offset method to offset the selected range, the offset
selection retains the size of the previously pasted range (that is, the
entire selected range is offset by the number of specified rows and
columns).
In addition, because the Paste method allows you to paste data to fill the
entire selected range, when you offset the selected range, if that range is
larger than the range of data you want to paste, Microsoft Excel will fill
the remaining cells in the selection.
WORKAROUND
To work around this problem, create a variable for your selection, and use
the Resize method to make the destination range the desired size. For
example, to create a destination range that is offset by the number of
columns in your selection, but is resized to one column, use the following
code:
x = Selection.Columns.Count
Selection.Offset(0, x).Resize(, 1).Select
Modification Type: | Minor | Last Reviewed: | 8/15/2003 |
---|
Keywords: | kberrmsg KB113703 |
---|
|