Application-defined or Object-defined error

nanofied

New Member
Joined
Aug 28, 2018
Messages
18
Hello guys. In the code below, I am trying to compare 2 column on Worksheet(DUMPSheet) (this worksheet has already been activated in the code before.) and add the missing cell into Worksheet(DTSheet). When trying to execute the code I get the "Application-defined or Object-defined error" Error.

Code:
Dim REFNO_GE As Variant
REFNO_GE = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).row).Value


Dim REFNO_DT As Variant
REFNO_DT = Range("K2:K" & Range("K" & Rows.Count).End(xlUp).row).Value


Dim x, y As Variant
Dim match As Boolean
Dim GECounter, DTCounter As Long
    
GECounter = 2
DTCounter = LastDTRow + 1
    
For Each x In REFNO_GE
    match = False
    For Each y In REFNO_DT
        If x = y Then match = True
    Next y
    If Not match Then
        Worksheets(DUMPSheet).Range(Cells(GECounter, 7)).Select
        Selection.Copy
        Worksheets(DTSheet).Range(Cells(DTCounter, 1)).Select
        Selection.Paste
        DTCounter = DTCounter + 1
    End If
    GECounter = GECounter + 1
Next
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
What happens with the code below?

Code:
    If Not Match Then
        Worksheets(DUMPSheet).Range(Cells(GECounter, 7)).Copy _
                Worksheets(DTSheet).Range(Cells(DTCounter, 1))
        DTCounter = DTCounter + 1
    End If

I am assuming that LastDTRow is being created somewhere earlier in the code.
 
Last edited:
Upvote 0
Code:
        Worksheets(DUMPSheet).Range(Cells(GECounter, 7)).Copy _
                Worksheets(DTSheet).Range(Cells(DTCounter, 1))
[\CODE]

At the above portion of the code I get the same error "Run-time Error 1004: [COLOR=#333333]Application-defined or Object-defined error"[/COLOR]
 
Upvote 0
Any sheet protection or merged cells? also when the error occurs if you hover your mouse over GECounter and DTCounter what values are shown?

Also is DUMPsheet a variable or a sheet name (same question for DTSheet)?
 
Last edited:
Upvote 0
They are not protected or merged as far as I know. But the cells that I wish to paste on is part of a table

DUMPSheet and DTSheet a string variable which have already been declared in the earlier code which are not shown

I will only be able to confirm again once I’m back at work 3 dayslater. Sorry for the inconvience and thank you for your assistance
 
Upvote 0
How about
Code:
If Not Match Then
    Worksheets(DUMPSheet).Range(Worksheets(DUMPSheet).Cells(GECounter, 7)).Copy _
      Worksheets(DTSheet).Range(Worksheets(DTSheet).Cells(DTCounter, 1))
    DTCounter = DTCounter + 1
End If
 
Upvote 0
Thanks Fluff, I missed that the Cells hadn't been qualified with the sheet :cool:
 
Upvote 0
How about
Code:
If Not Match Then
    Worksheets(DUMPSheet).Range(Worksheets(DUMPSheet).Cells(GECounter, 7)).Copy _
      Worksheets(DTSheet).Range(Worksheets(DTSheet).Cells(DTCounter, 1))
    DTCounter = DTCounter + 1
End If

Hi Fluff, I am still getting the same error.
 
Upvote 0
Any sheet protection or merged cells? also when the error occurs if you hover your mouse over GECounter and DTCounter what values are shown?

Also is DUMPsheet a variable or a sheet name (same question for DTSheet)?

I have checked, there is no sheet protection or any merged cells.

And GECounter and DTCounter is 2 and 117 respectively. The values are as what I desired.
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,942
Latest member
sharmarick

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