Hi Guys,
I'm trying to rearrange some data and having trouble with getting it to correctly loop through a list.
Basically I have data in columns 1-39 with no gaps. Column N contains names. I am trying to create something which takes the name on any given row (From N2 down) and searches for matches in all rows below given row. Each time it finds a match it copies all the data from each row and pastes it all on the same row which the original name came from. Then this would loop only the next cell so N3, take the name, find matched below paste all the the right etc.
So i can get the code to do the procedure i want one time, on N2, but then cant get that to loop through all the names AND find all the below matched and paste them on the same row.
At the moment it's looping through the N column (somehow) and pasting everything on the first row. I cant correctly make it offset the paste to BB3 etc. without getting an error.
This is what i have:
It's a bit messy as the loop is sort of just stuck in there. Any help would be much appreciated.
Thanks
Dave
I'm trying to rearrange some data and having trouble with getting it to correctly loop through a list.
Basically I have data in columns 1-39 with no gaps. Column N contains names. I am trying to create something which takes the name on any given row (From N2 down) and searches for matches in all rows below given row. Each time it finds a match it copies all the data from each row and pastes it all on the same row which the original name came from. Then this would loop only the next cell so N3, take the name, find matched below paste all the the right etc.
So i can get the code to do the procedure i want one time, on N2, but then cant get that to loop through all the names AND find all the below matched and paste them on the same row.
At the moment it's looping through the N column (somehow) and pasting everything on the first row. I cant correctly make it offset the paste to BB3 etc. without getting an error.
This is what i have:
Code:
[/COLOR]Sub finddata()
Dim name As String
Dim finalrow As Integer
Dim startrow As Integer
Dim i As Integer
Dim offset As Integer
Sheets("Sheet1").Range("BB2:CAA5000").ClearContents
Range("BB2").Select
ActiveCell.FormulaR1C1 = "0"
Range("BC2").Select
ActiveCell.FormulaR1C1 = "0"
name = Sheets("Sheet1").Range("N2").Value 'Needs to loop down the N column from N2
startrow = Sheets("sheet1").Range("N2").Row 'Needs to be the current row in the loop
finalrow = Sheets("sheet1").Range("C100000").End(xlUp).Row
Dim cell As Range
For Each cell In ActiveSheet.Range("N2:N1000")
For i = startrow To finalrow
If Cells(i, 14) = name Then
Range(Cells(i, 1), Cells(i, 39)).Copy
Range("BB2").Select
Selection.End(xlToRight).Select
Selection.offset(0, 1).PasteSpecial xlPasteValues
End If
Next i
Next cell
End Sub
It's a bit messy as the loop is sort of just stuck in there. Any help would be much appreciated.
Thanks
Dave
Last edited: