lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 2))
Searchfor = Cells(1, 5)
For i = 1 To lastrow
If inarr(i, 1) = Searchfor Then
Cells(1, 6) = inarr(i, 2)
Exit For
End If
Next i
Sub test2()
With Worksheets("sheet1")
lastrow = .Cells(Rows.Count, "B").End(xlUp).Row
inarr = Range(.Cells(1, 1), .Cells(lastrow, 36))
End With
With Worksheets("sheet2")
lastrow2 = .Cells(Rows.Count, "A").End(xlUp).Row
search4 = Range(.Cells(1, 1), .Cells(lastrow2, 1))
End With
For i = 1 To lastrow2
For j = 1 To lastrow
If search4(j, 1) = inarr(i, 2) Then
For k = 3 To 36
' do what ever you want to do with the values from C to AJ here
MsgBox (inarr(i, k))
Next k
End If
Next j
Next i
End Sub
Sub test()
Dim txt As String
With Worksheets("sheet1")
lastrow = .Cells(Rows.Count, "B").End(xlUp).Row
inarr = Range(.Cells(1, 1), .Cells(lastrow, 36))
End With
With Worksheets("sheet2")
lastrow2 = .Cells(Rows.Count, "A").End(xlUp).Row
search4 = Range(.Cells(1, 1), .Cells(lastrow2, 1))
End With
For i = 1 To lastrow
For j = 1 To lastrow2
If search4(j, 1) = inarr(i, 2) Then
For k = 3 To 36
' do what ever you want to do with the values from C to AJ here
txt = inarr(i, k)
MsgBox (txt)
Next k
End If
Next j
Next i
End Sub
Yes you are missing what is happening ,. ther is a double loop the outside loop I = 1 to lastrow loops down the rows in inarr whic his the dat from sheet 1 ( in my code)I think this is because the number of rows in the data set on sheet 2 is significantly higher than what's in sheet 1, so (J,1)<>(I,2). Or am i missing what this actually does?