In excel I have four columns. There are numbers in the first column, the second column is blank, the third also contains numbers and the fourth contains text.
I want to check each value in the first column and check if it exists in the third column. If it does the value in the fourth column next to the corresponding third column should be copied up to the second column next to the corresponding first column.
I am getting the error compile error. Next without For. Here is my code so far:
Sub Compare() Dim colA As Integer, colB As Integer colA = Columns("A:A").Rows.Count colB = Columns("C:C").Rows.Count For I = 2 To colA 'loop through column A For j = 2 To colB 'loop through column C ' If a match is found: If Worksheets("Sheet1").Cells(I, 1) = Workshee("Sheet1").Cells(j, 3) Then ' Copy Worksheets("Sheet1").Cells(j, 4) = Worksheets("Sheet1").Cells(I, 2) 'Exit For Next j Next I End Sub
If. AddEnd IfbeforeNext j. Btw, a quick google search of "Next without For" would have given the same answer.