I have the below code but I need a bit of help changing it:
Currently, it looks for a string in column A in sheet 2, if it finds it, it puts a value in column B on that same row....but it also puts some random values at the end of the list because my error handler is wrong...
What I need is:
IF you find it, then put a value in the adjacent cell, then exit macro and
IF the item doesn't exist, then put the item at the end of the list
Any help would be appreciated.
Code
Sub test()
y = "a"
X = "b"
On Error GoTo errhandler
rng1 = Sheets(2).Range("A1:A5000")
Dim l As Long
l = Application.WorksheetFunction.Match("12348", rng1, 0)
Sheets(2).Cells(l, 2) = "x"
errhandler:
k = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
Sheets(2).Cells(k, 1) = y
Sheets(2).Cells(k, 2) = X
End Sub
Display More