Runtime Error 1004 in vba excel
Hi,
I am trying to import data from an excel file to another using a macro.
The problem is When I paste the values I get the following error: "This operation requires that the cells combine with the same size" (error 1004 runtime)
The macro code is as follows, and the error is given by the line preceded by (*):
Code:
Workbooks.Open Filename: = "L: \ myFile.xls", _
UpdateLinks: = 0
Sheets ( "tab02). Select
Range ( "A4: T47"). Select
Selection.Copy
Windows (MyFile2.xls). Activate
Sheets ( "Files"). Select
Range ( "A4"). Select
Selection.PasteSpecial Paste: = xlFormats, Operation: = xlNone, SkipBlanks: = _
False, Transpose: = False
(*) Selection.PasteSpecial Paste: = xlValues, Operation: = xlNone, SkipBlanks: = _
False, Transpose: = False
Columns ( "A: A"). EntireColumn.AutoFit
Thank you very much in advance.
Re: Runtime Error 1004 in vba excel
You receive a "Runtime error 1004 , When you try to copy and to paste filtered data programmatically in a Microsoft Office Excel 2003 workbook, you receive one of the following error messages:
See here for more helps http://support.microsoft.com/kb/905164
Re: Runtime Error 1004 in vba excel
Hello.
Try the following code:
Code:
Workbooks.Open Filename: = "c: \ myFile.xls" UpdateLinks: = 0
Sheets ( "tab02). Select
Worksheets ( "tab02). Range (" A4: K49 "). Select
Selection.Copy
Windows (MyFile2.xls). Activate
Sheets ( "Files"). Select
Worksheets ( "Files"). Range ( "A4"). Select
Selection.PasteSpecial Paste: = xlFormats, Operation: = xlNone, SkipBlanks: = False, Transpose: = False
Selection.PasteSpecial Paste: = xlValues, Operation: = xlNone, SkipBlanks: = False, Transpose: = False
Columns ( "A: A"). EntireColumn.AutoFit
The key is to use:
Worksheets ( "tab02). Range (" A4: K49 "). Select
Instead of:
Range ( "A4: K49"). Select
Although it has been selected the sheet where you want to take the information during the execution of the VBA does not recognize it.
I hope this information serves you, but do not hesitate to ask again.