Solved

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

Posted on 2014-10-31
4
85 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now