I have a big problem trying to make this script works. I need to create a script on vba-excel that compares two lists that are two ranges of cells, and that if a value from the first list is not found in the second, copy it to the end of the second list and paste the position of a nearby cell the cell where it is. But i'm getting the Run-time error '1004': Application-defined or operation-defined error. My script is as follows:
Dim CellA As Object
Dim ListOLD As Range
Dim ListNEW As Range
Dim FinalA As Long
Dim FinalC As Long
FinalA = Worksheets("Sheet1").Range("K2").End(xlToRight).Column
FinalC = Worksheets("Sheet2").Range("A9").End(xlDown).Row
Set ListOLD = Worksheets("Sheet1").Range(Cells(11, 2), Cells(FinalA, 2))
Set ListNEW = Worksheets("Sheet2").Range("A9:A" & FinalC)
For Each CellA In ListNEW
If Application.WorksheetFunction.CountIf(ListOLD, CellA) = 0 Then
Worksheets("Sheet2").Select
Worksheets("Sheet2").Range(CellA.Column, CellA.Row).Select
Selection.Copy
Worksheets("Sheet1").Range(Cells(11, 2), Cells(FinalA, 2)).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Application.CutCopyMode = False
End If
Next Celda
End Sub
I'm pretty new to this, if anyone can give me a hand it would help me a lot. I'm working on this all day!!! Ty