I have a macro to check sheet1 if the value in column A matches the value in the same column in sheet2, and if so, it copies the adjacent cell for each matched value from sheet1 into sheet2. Below is what I have so far, but I keep getting 'run time error 9' on the lastrowadd line and am not sure why. Any help would be appreciated :)
Sub CopyAdjacent()
Dim i As Long, j As Long, colStatus As Long, lastrowAdd As Long, lastrowRemove As Long
colStatus = 2 'your status column number
lastrowAdd = Sheets(“Sheet1”).Cells(Sheets(“Sheet1”).Rows.Count, 1).End(xlUp).Row
lastrowRemove = Sheets(“Sheet2”).Cells(Sheets(“Sheet2”).Rows.Count, 1).End(xlUp).Row
For i = 1 To lastrowAdd
For j = 1 To lastrowRemove
If Sheets(“Sheet1”).Cells(i, 1).Value = Sheets(“Sheet2”).Cells(j, 1).Value Then
Sheets(“Sheet2”).Cells(j, colStatus).Value = Sheets(“Sheet1”).Cells(i, colStatus).Value
End If
Next j
Next i
End Sub
Sheets(“Sheet1”).Cells(Sheets(“Sheet1”).Rows.Count, 1).End(xlUp).RowTry changing this toSheets(“Sheet1”).Rows.Count-1and see what happen - Saechel