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: 10
  • debug1.png
    debug1.png
    109.8 KB · Views: 10

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,214,788
Messages
6,121,580
Members
449,039
Latest member
Arbind kumar

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