Hi
I've put some more comments into the code. See if that helps. Don't hesitate to ask questions tho...
Sub aaa()
'create and set aliases for the relevant sheets
Dim OutSH As Worksheet, DataSH As Worksheet
Set OutSH = Sheets("DataPEs")
Set DataSH = Sheets("Sheet1")
'activate the sheet with data
DataSH.Activate
'cycle through each item in the data sheet
For Each ce In Range("F2:F" & Cells(Rows.Count, "F").End(xlUp).Row)
'find a non blank data sheet cell
If Not IsEmpty(ce) Then
'do a find to see if the item exists in the output sheet
Set findit = OutSH.Range("B:B").Find(what:=ce.Value, lookat:=xlWhole)
'if the item is found
If Not findit Is Nothing Then
'determine data column by getting the lastmost data column
If Not IsEmpty(Cells(ce.Row + 1, "Q")) Then
datacol = "Q"
ElseIf Not IsEmpty(Cells(ce.Row + 1, "M")) Then
datacol = "M"
Else
datacol = "K"
End If
'initialise a loop counter
i = 1
'loop through the items in column C and find where they exist in the output sheet
While Not IsEmpty(ce.Offset(i, -3))
'set a range to search for the column C sub items
Set rng = findit.Offset(1, 0).Resize(6, 1)
'do a find rng to see if the sub item exists
Set findit2 = rng.Find(what:=Right(ce.Offset(i, -3).Value, Len(ce.Offset(i, -3).Value) - 3))
'if the sub item exists, then paste in the data
If Not findit2 Is Nothing Then findit2.Offset(0, 2).Value = Cells(ce.Offset(i, 0).Row, datacol).Value
'increment the counter
i = i + 1
Wend
End If
End If
Next ce
End Sub
rylo
Bookmarks