Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-10-31
4
Medium Priority
?
93 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

972 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