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

jsnide

New Member
Joined
Apr 13, 2022
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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)?
 
Upvote 0
Hi,

maybe it's just missing dots...

VBA Code:
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
 
Last edited:
Upvote 0
Further to what Joe has said, what is the error message & number you get?
 
Upvote 0
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!
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top