S
Steve
Hello everybody,
I am fairly new to VBA and I have come to a point where I need some
help. I am trying to copy from one excel file to another. I could do
that using various Windows.Activate, Wokrsheet.activate lines and i
works that way. But I would like to do it in a more elegant way. I am
using the following code:
Do
Application.Workbooks(filename).Worksheets("test2").Range(Cells(counter,
1), Cells(counter, 6)).Copy
Destination:=Application.Workbooks(filename).Worksheets("test2").Range(Cells(counter,
8), Cells(counter, 13))
counter = counter + (60 * values_per_sec)
targetcounter = targetcounter + 1
Loop While counter <= nr_of_rec
filename has been defined by the user, nr_of_rec and values_per_sec
are read out of the file "filename".
Now, while the code above is working fine, I do not want to copy and
paste in the same workbook (as the code above does), but into another,
thus I write:
Application.Workbooks(filename).Worksheets("test2").Range(Cells(counter,
1), Cells(counter, 6)).Copy
Destination:=Application.Workbooks("Auswerter.xls").Worksheets("Data").Range(Cells(targetcounter,
1), Cells(targetcounter, 6))
"Auswerter.xls" is the target file and "Data" the targer worksheet.
But this returns a runtime error 1004 "Application-defined or Object-
defined error".
It would be great if someone could explain to me, why I get this error
and how I could get rid of it.
Thanks a lot!
Steve
I am fairly new to VBA and I have come to a point where I need some
help. I am trying to copy from one excel file to another. I could do
that using various Windows.Activate, Wokrsheet.activate lines and i
works that way. But I would like to do it in a more elegant way. I am
using the following code:
Do
Application.Workbooks(filename).Worksheets("test2").Range(Cells(counter,
1), Cells(counter, 6)).Copy
Destination:=Application.Workbooks(filename).Worksheets("test2").Range(Cells(counter,
8), Cells(counter, 13))
counter = counter + (60 * values_per_sec)
targetcounter = targetcounter + 1
Loop While counter <= nr_of_rec
filename has been defined by the user, nr_of_rec and values_per_sec
are read out of the file "filename".
Now, while the code above is working fine, I do not want to copy and
paste in the same workbook (as the code above does), but into another,
thus I write:
Application.Workbooks(filename).Worksheets("test2").Range(Cells(counter,
1), Cells(counter, 6)).Copy
Destination:=Application.Workbooks("Auswerter.xls").Worksheets("Data").Range(Cells(targetcounter,
1), Cells(targetcounter, 6))
"Auswerter.xls" is the target file and "Data" the targer worksheet.
But this returns a runtime error 1004 "Application-defined or Object-
defined error".
It would be great if someone could explain to me, why I get this error
and how I could get rid of it.
Thanks a lot!
Steve