Help In Identifying "Object Not Defined" Error

evxret

New Member
Joined
Apr 8, 2022
Messages
38
Office Version
  1. 365
Platform
  1. Windows
Hello all,
I am currently attempting to write a macro that filters out New orders, (Anything with N/A in column 11, as shown as first part of code), Copies any visible (filtered) cells, and pastes them onto the first empty line on Column B on another sheet.

Here is what I have written here.
VBA Code:
'   ``Filter New Orders
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("$A$1:$K$1000").AutoFilter Field:=11, Criteria1:="#N/A"
    
    ''Set Variables
    Dim LR As Integer
     Set LR = Sheets("ALL Orders Database").Range("C2").End(xlDown).Row
    

    
    ''Copy Customer Cells After Filter has been applied
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("C2:C").SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
   

    ''Pastes Customer Info on First Open Cell on Column D (First Open Cell Variable pulled from Column C)  
    Sheets("ALL Orders Database").Activate
    Worksheets("ALL Orders Database").Range("D2:D" & LR + 1).PasteSpecial Paste:=xlPasteValues

When I Run the code, it highlights my "Set LR" line and gives me "Object not defined" Error, I've tried to Dim LR as an integer, long, I've tried adjusting the code defining my row count.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try changing

Set LR = Sheets("ALL Orders Database").Range("C2").End(xlDown).Row

to

LR = Sheets("ALL Orders Database").Range("C2").End(xlDown).Row
 
Upvote 0
Try changing

Set LR = Sheets("ALL Orders Database").Range("C2").End(xlDown).Row

to

LR = Sheets("ALL Orders Database").Range("C2").End(xlDown).Row
Thank you! This helped. I am now though, getting a 1004 runtime error, I had to fix the code in a few other spots so here is the new example.
VBA Code:
'   ``Filter New Orders
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("$A$1:$K$1000").AutoFilter Field:=11, Criteria1:="#N/A"
    
    ''Set Variables
    Dim LR As Long
    Dim DBLR
    LR = Sheets("ALL Orders Database").Range("C2").End(xlDown).Row
    DBLR = Sheets("Test Ship Report").Range("B2").End(xlDown).Row

    
    ''Copy Customer
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("C2:C" & DBLR + 1).SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Sheets("ALL Orders Database").Activate
    Worksheets("ALL Orders Database").Range("D2:D" & LR + 1).PasteSpecial Paste:=xlPasteValues
It is highlighting the very last line in the code as the error. Can you spot anything wrong just by looking at it? I appreciate your help so much.
 
Upvote 0
Thank you! This helped. I am now though, getting a 1004 runtime error, I had to fix the code in a few other spots so here is the new example.
VBA Code:
'   ``Filter New Orders
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("$A$1:$K$1000").AutoFilter Field:=11, Criteria1:="#N/A"
   
    ''Set Variables
    Dim LR As Long
    Dim DBLR
    LR = Sheets("ALL Orders Database").Range("C2").End(xlDown).Row
    DBLR = Sheets("Test Ship Report").Range("B2").End(xlDown).Row

   
    ''Copy Customer
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("C2:C" & DBLR + 1).SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Sheets("ALL Orders Database").Activate
    Worksheets("ALL Orders Database").Range("D2:D" & LR + 1).PasteSpecial Paste:=xlPasteValues
It is highlighting the very last line in the code as the error. Can you spot anything wrong just by looking at it? I appreciate your help so much.
Just noticed my 2nd variable was missing a declaration, Fixed it and same issue.
 
Upvote 0
Are you trying to paste the data into D2?
 
Upvote 0
Are you trying to paste the data into D2?
I am trying to paste the data into column D, based on the first open cell in Column C. Information is completely filled in Column C which is why it will be the identifier for where to paste data. (Column D has blanks so If I try to set a variable to find the last row it will not be able to find it, because technically its sometimes blank.) I hope this makes sense.
 
Upvote 0
Ok, how about
VBA Code:
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("C2:C" & DBLR + 1).SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Worksheets("ALL Orders Database").Range("D" & LR).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Solution
Ok, how about
VBA Code:
    Sheets("Test Ship Report").Activate
    Sheets("Test Ship Report").Range("C2:C" & DBLR + 1).SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Worksheets("ALL Orders Database").Range("D" & LR).PasteSpecial Paste:=xlPasteValues
This worked, Thank you!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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