On 9 Apr., 17:04, Vergel Adriano
<VergelAdri...@discussions.microsoft.com> wrote:
> Steve,
>
> The only line where I think your current code would error outis on this line:
>
> Set trng =
> Application.Workbooks("Auswerter.xls").Worksheets("Data").Range(Cells(targetcounter,
> 1), Cells(targetcounter, 6))
>
> You will get the 1004 error if the line executes and the "Data" worksheet is
> not the active sheet. I believe the call to Cells(targetcounter, x) will
> return a range in the current active sheet in the current active workbook.
> So, try that line like this and see if it helps:
>
> With Application.Workbooks("Auswerter.xls").Worksheets("Data")
> Set trng = .Range(.Cells(targetcounter, 1), .Cells(targetcounter, 6))
> End With
>
> --
> Hope that helps.
>
> Vergel Adriano
>
> "Steve" wrote:
> > On 9 Apr., 15:48, Vergel Adriano
> > <VergelAdri...@discussions.microsoft.com> wrote:
> > > You need to make sure that the target workbook is open, then try it this way:
>
> > > Dim rng As Range
> > > With Application.Workbooks(Filename).Worksheets("test2")
> > > Set rng = .Range(.Cells(counter, 1), .Cells(counter, 6))
> > > rng.Copy
> > > Destination:=Application.Workbooks("Auswerter.xls").Worksheets("Data").Range(rng.Address)
> > > End With
>
> > > --
> > > Hope that helps.
>
> > > Vergel Adriano
>
> > Thanks for the help. Your approach works fine, it finally copies it to
> > the target file. But I do not really get anywhere, because I paste the
> > data to the same adress as I took them from. My intention is to copy
> > every 20th or so line into a different file (which I can do now,
> > thanks to your help). But in that file ("Auswerter.xls") the lines are
> > supposed to be directly underneath one another. So, what I did was
> > change the rng.Adress part to an different range:
>
> > Dim counter As Long
> > counter = 21
> > Dim targetcounter As Integer
> > targetcounter = 1
> > Dim rng As Range
> > Dim trng As Range 'this is the target range
>
> > Do
> > Set trng =
> > Application.Workbooks("Auswerter.xls").Worksheets("Data").Range(Cells(targetcounter,
> > 1), Cells(targetcounter, 6))
> > With Application.Workbooks(filename).Worksheets("test2")
> > Set rng = .Range(.Cells(counter, 1), .Cells(counter, 6))
> > rng.Copy Destination:=trng
> > End With
> > counter = counter + (60 * values_per_sec) 'this counter advances
> > faster and thus many lines in the original file are skipped, as is
> > intended.
> > targetcounter = targetcounter + 1 ' the targetcounter is advancing one
> > step at a time, thus going down one line at a time in the targetsheet.
> > Loop While counter <= nr_of_rec
>
> > And this again generates the same error 1004 as before. I am really
> > stuck at the moment. How can it be, that the program can copy and
> > paste to the same adress in different files but not to different
> > adresses in different files?
>
> > help would be greatly appreciated! Thanks!
Hey, thanks a lot! It worked!
Greets Steve
|