Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
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…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

762 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

20 Experts available now in Live!

Get 1:1 Help Now