# Sheets().Range().Copy - Not working all of a sudden



## jsnide (Jan 5, 2023)

Been using the below VBA for years - no issue.  All of a sudden i get a break on the *bolded* line.  Guessing something to do with how I use 'Range' as everything else in VBA referencing 'Sheets' is fine.  Any advice would be greatly appreciated:

Sheets("Blotter").Select
Range("AE2:AH2").Select
Selection.AutoFill Destination:=Range("AE2:AH150000")

Sheets("Blotter2").Select
Range("AD2:AD2").Select
Selection.AutoFill Destination:=Range("AD2:AD150000")

*Sheets("TOTALS").Range("AM2:AN2").Copy*
With Sheets("TOTALS").Range("D" & Rows.Count).End(xlUp).Offset(1)
    .PasteSpecial Paste:=xlPasteColumnWidths
    .PasteSpecial Paste:=xlPasteValues
End With

Sheets("TOTALS").Range("AM3:AN3").Copy
With Sheets("TOTALS").Range("J" & Rows.Count).End(xlUp).Offset(1)
    .PasteSpecial Paste:=xlPasteColumnWidths
    .PasteSpecial Paste:=xlPasteValues
End With


----------



## Joe4 (Jan 5, 2023)

Have you placed this code in a General Module or a Sheet Module?
Is the "TOTALS" sheet visible or hidden?
Is there anything special about the range AM2:AN2 (is it protected or part of a merged cell)?


----------



## HaHoBe (Jan 5, 2023)

Hi,

maybe it's just missing dots...


```
With Sheets("Blotter")
'  'really fill up to 1500000?
'  Dim lngLast As Long
'  lngLast = .Cells(.Rows.Count, "A").End(xlUp).Row
'  .Range("AE2:AH2").AutoFill Destination:=.Range("AE2:AH" & lngLast)
'  .Range("AD2:AD2").AutoFill Destination:=.Range("AD2:AD" & lngLast)
  .Range("AE2:AH2").AutoFill Destination:=.Range("AE2:AH150000")
  .Range("AD2:AD2").AutoFill Destination:=.Range("AD2:AD150000")
End With

With Sheets("TOTALS")
  .Range("D" & .Rows.Count).End(xlUp).Offset(1).Resize(1, 2).Value = .Range("AM2:AN2").Copy
  .Range("J" & .Rows.Count).End(xlUp).Offset(1).Resize(1, 2).Value = .Range("AM3:AN3").Copy
End With
```

Holger


----------



## Fluff (Jan 5, 2023)

Further to what Joe has said, what is the error message & number you get?


----------



## jsnide (Jan 5, 2023)

Fluff said:


> Further to what Joe has said, what is the error message & number you get?


Error is:

*Runtime error '-2147319767 (80028029)

"Invalid forward reference; or refercence to uncompiled type"*

Thanks all for your help!


----------



## Fluff (Jan 5, 2023)

That's not an error I've ever come across, so not sure how to deal with it.
One option that might help, in the VB Editor under Tools, References check one of the boxes (it doesn't matter which) & then under Debug click Compile.
You can then remove the reference you just added & try running the code again.


----------



## jsnide (Jan 5, 2023)

Fluff said:


> That's not an error I've ever come across, so not sure how to deal with it.
> One option that might help, in the VB Editor under Tools, References check one of the boxes (it doesn't matter which) & then under Debug click Compile.
> You can then remove the reference you just added & try running the code again.


Will do - appreciate you taking the time to try and assist


----------

