I am getting stuck between two errors. I am trying to create a module to copy data from one tab of a workbook and then paste it into another. When I run code A:
Dim N As Range
Dim Out As Range
Dim c As Range
Dim StartCell As Range
Set StartCell = Worksheets("Sheet 2").Range("A1")
Set c = Sheets("Sheet 1").Range("Named_Range").Cells(1, 1)
Set N = Sheets("Sheet 1").Range(c, c.Cells(10, 1)) 'Using "c" here to select a dynamically chosen portion of a named range, "10" chosen for example
Set Out = StartCell.Offset(, 2)
'Copy / paste
Worksheets("Sheet 1").N.Copy (Worksheets("Sheet 2").Out)
I get
Run-time error '438': Object doesn't support this property or method
But when I run code B:
Dim N As Range
Dim Out As Range
Dim c As Range
Dim StartCell As Range
Set StartCell = Worksheets("Sheet 2").Range("A1")
Set c = Sheets("Sheet 1").Range("Named_Range").Cells(1, 1)
Set N = Sheets("Sheet 1").Range(c, c.Cells(10, 1)) 'Using "c" here to select a dynamically chosen portion of a named range, "10" chosen for example
Set Out = StartCell.Offset(, 2)
'Copy / paste
N.Copy (Out)
I get
Run-time error '1004': Copy method of Range class failed
My understanding is that Code A isn't working because of something to do with "late binding".
I believe code B isn't working because I need to select the relevant sheets.
Additionally, I'll note that when I try to specify
Set Out = Worksheets("Sheet 2").StartCell.Offset(, 2)
I am also getting a heavy dose of error '438'. I cannot understand why, other than that I need to do Worksheets("Sheet 2").Select
before doing my Set Out
but again I understand that it's not a best practice to rely on Select
that way.
What is an Excel wonk to do here? I feel like good ol' MS has me cornered between a rock and a hard place here.