The issue is that VBA does not know in which worksheet these cells Cells(1, 1), Cells(10, 2)
are because you did not specify it. Therefore you get an error.
Make sure you specify a worksheet for every Cells
, Range
, Rows
or Columns
object. If you don't specify it Excel starts guessing which sheet you mean (based on the scope the code is written in), and it might assume something else than you did. In most cases a Cells
without specifying a sheet will be the same as ActiveSheet.Cells
.
So correct would be:
Worksheets("Data").Range(Worksheets("Data").Cells(1, 1), Worksheets("Data").Cells(10, 2)).Copy Worksheets("Tabelle1").Range(Worksheets("Tabelle1").Cells(1, 1), Worksheets("Tabelle1").Cells(10, 2))
Or better:
Dim Source As Range
With ThisWorkbook.Worksheets("Data")
Set Source = .Range(.Cells(1, 1), .Cells(10, 2))
End With
Dim Destination As Range
With ThisWorkbook.Worksheets("Tabelle1")
Set Destination = .Range(.Cells(1, 1), .Cells(10, 2))
End With
Source.Copy Destination
or something like
Dim wsSrc As Worksheet
Set wsSrc = ThisWorkbook.Worksheets("Data")
Dim wsDest As Worksheet
Set wsDest = ThisWorkbook.Worksheets("Tabelle1")
wsSrc.Range(wsSrc.Cells(1, 1), wsSrc.Cells(10, 2)).Copy wsDest.Range(wsDest.Cells(1, 1), wsDest.Cells(10, 2))