Article ID: 113703
Article Last Modified on 8/15/2003
SELECTION.OFFSET(rowOffset, columnOffset).SELECTin conjunction with the Copy and Paste methods, you may receive the following unexpected results:
x = Selection.Columns.Count
Selection.Offset(0, x).Resize(, 1).Select
A B C
-------------------------
1 100 200 300
2 100 200 300
3 100 200 300
4 100 200 300
5 100 200 300
Sub Test()
' Select the first two columns from the source sheet
Sheets("Sheet2").Select
Range("A1:B5").Select
Selection.Copy
' Paste the data into the destination sheet
Sheets("Sheet1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
' Copy the third column from the destination sheet
Sheets("Sheet2").Select
Range("C1:C5").Select
' Paste it into the destination area
Selection.Copy
Sheets("Sheet1").Select
Selection.Offset(0,2).Select
ActiveSheet.Paste
End Sub
A B C D
---------------------------------
1 100 200 300 300
2 100 200 300 300
3 100 200 300 300
4 100 200 300 300
5 100 200 300 300
To edit this macro so that the data is copied correctly, replace the line
of code that reads:
Selection.Offset(0,2).Select
-with-
x = Selection.Columns.Count
Selection.Offset(0, x).Resize(, 1).Select
When you run the macro with this change included, the copied data is pasted
once into the correct paste range.
Additional query words: 5.00c 7.00a XL
Keywords: kberrmsg KB113703