VBA - 1004 Error #Ref

F4TMAN

New Member
Joined
Jun 29, 2020
Messages
25
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello,

I'm back again, let me just say that I found this website to be very helpful.

I currently have a script that was created by an external source. I don't have access to that person anymore. When I try running the script its returning a 1004 error (see attachment). From what i can see certain data is suppose to be paste as values but for some reason its coming up as #ref error. Is there anyway I can go about this?


Thanks in advance

VBA Code:
Sub Budget_Data()
'
' Budget_Data Macro
'
' Keyboard Shortcut: Ctrl+j
'
    Range("N5").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("P&L Scrubbed").Select
    Range("A1").Select
    ActiveSheet.Paste
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.AutoFilter
    Range("A1").Select
    ActiveSheet.Range("$A$1:$I$3183").AutoFilter Field:=1, Criteria1:="="
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Rows("2:3183").Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Delete Shift:=xlUp
    Range("A1").Select
    Selection.AutoFilter
End Sub
 

Attachments

  • ref error.png
    ref error.png
    104.3 KB · Views: 23
  • debug1.png
    debug1.png
    109.8 KB · Views: 21

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
If the range of cells in the copy area have formulas in them, when you paste to
Sheets("P&L Scrubbed").Range("A1")....the formulas are probably trying to refer to locations that don't exist...ie, anything pre N5 references.
Maybe this way
VBA Code:
Range("N5").CurrentRegion.Copy
    Sheets("P&L Scrubbed").Range("A1").PasteSpecial Paste:=xlPasteValues
    Sheets("P&L Scrubbed").Select
    Range("A1").Select
    ActiveSheet.Range("$A$1:$I$3183").AutoFilter Field:=1, Criteria1:="="
 
Upvote 0
UNTESTED
VBA Code:
Sub Budget_Data()
' Budget_Data Macro
' Keyboard Shortcut: Ctrl+j
Range("N5").CurrentRegion.Copy
Sheets("P&L Scrubbed").Range("A1").PasteSpecial Paste:=xlPasteValues
Sheets("P&L Scrubbed").Select
Range("A1").Select
ActiveSheet.Range("$A$1:$I$3183").AutoFilter Field:=1, Criteria1:="="
Rows("2:3183").SpecialCells(xlCellTypeVisible).EntireRow.Delete
Selection.AutoFilter
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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