Application Defined or Object Defined Error in CopyPaste

527 Views Asked by At

For some reason I am getting an error, but I cannot find out why. It happens on the copy/paste, but I dont see how it would cause it. Please help

Sub CopyMain()
RowCountBack = 2
Dim n As Integer
RowCount = RowCount / 2
RowCountConst = RowCount
RowCount = RowCount + 1
For n = 1 To 100
    'If Cells(RowCount, 10).Value = "AR_Mag (ppm)" Then
    If InStr(1, Worksheets("RAW").Cells(RowCount, 7).Value, "AR_Mag", vbTextCompare) > 0 Then
        'Sheets("RAW").Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy
        WkSht.Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy Destination:= _
            Worksheets("AR_MAG").Range("a5") _
            .End(xlDown).Offset(2, 0)
        RowCount = RowCount + RowCountConst
        RowCountBack = RowCountBack + RowCountConst
    End If

This is the code after much editing. The original is here with a similar error

If InStr(1, Worksheets("RAW").Cells(RowCount, 7).Value, "AR_Rot", vbTextCompare) > 0 Then
        wkb.Sheets("AR_ROT").Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Value = wkb.Sheets("RAW").Range(Cells(RowCountBack, 1), Cells(RowCount, 10))
        RowCount = RowCount + RowCountConst
        RowCountBack = RowCountBack + RowCountConst
    End If

As you can see both ifs serve a similar purpose

1

There are 1 best solutions below

0
On BEST ANSWER

I dont know why, but here is the working version

Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy Destination:=Sheets("AR_MAG").Range("A2")