Solved

MS Excel VBA - Can not copy paste rows if columns total 298

Posted on 2014-10-31
4
87 Views
Last Modified: 2014-11-01
I run the below code fine 99.9% of the time, but today I hit a problem when the sheet I was trying to copy had 298 columns.  I got an error that the size/shape did not match between source and target.

How can I resoleve the issue.  If I do a manual cut and paste I do not get an error.


Sub dfsjijsdfkoiewa()

    Sheets("Sheet1").Cells.Copy

    Sheets("Sheet2").Cells.PasteSpecial Paste:=xlPasteValues............................................

    Application.CutCopyMode = False

End Sub
0
Comment
Question by:upobDaPlaya
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40416886
Where you do specify/select the range of cells to copy?

You could change the second command to show the anchor cell only, for example:
Sheets("Sheet2").Range("A1").PasteSpecial Paste:=xlPasteValues

-Glenn
0
 

Author Comment

by:upobDaPlaya
ID: 40417266
Tried that and i am getting an error..i will paste the error when i get home..
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40417427
If you're using a version of Excel earlier than 2007 - or pasting into a 97-2003 file (.xls) you'll encounter this error because those versions were limited to 256 columns.
0
 

Author Closing Comment

by:upobDaPlaya
ID: 40417640
Glenn...that was it...once I changed the export code to xlsx (I have code in another module that creates the source workbook which was being done in xls)  and I did your code it woked beautiful.  Thanks !
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question