hello
I have a list of names, some of which occur several times, with values attributed to the names in the adjacent column. I want a list in which the names occur once and the all the values belonging to the name appear in the row the name is in. I have code which almost does it, but not quite.
My data looks like this example:
fred 10
dave 1
jill 4
fred 11
marc 74
I want:
dave 1,
fred 10,11
jill 4,
marc 74,
so I start with a list
dave
fred
jill
marc
and then run my code.
My code is:
Option Explicit
Sub Compare()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim i As Long, j As Long, LR As Long
Set ws1 = Sheets("Deutsch")
Set ws2 = Sheets("Deutsch2")
For j = 2 To 182
i = 2
Do
If ws1.Cells(i, 5) = ws2.Cells(j, 5) Then
ws2.Cells(j, 6).Value = ws1.Cells(i, 6).Value
End If
i = i + 1
If i = 314 Then
Exit Do
End If
Loop Until ws2.Cells(j, 6) <> ""
Do
If ws1.Cells(i, 5) = ws2.Cells(j, 5) Then
ws2.Cells(j, 7).Value = ws1.Cells(i, 6).Value
End If
i = i + 1
If i = 314 Then
Exit Do
End If
Loop Until ws2.Cells(j, 7) <> ""
If i < 314 Then
Do
If ws1.Cells(i, 5) = ws2.Cells(j, 5) Then
ws2.Cells(j, 8).Value = ws1.Cells(i, 6).Value
End If
i = i + 1
If i = 314 Then
Exit Do
End If
Loop Until ws2.Cells(j, 8) <> ""
End If
Next j
End Sub
It works fine for a while, then gives me an 'error 1004 object or application error' at always the same point, when it gets to row 144 in the destination list.
The editor tells me I should debug the line 'If ws1.Cells(i, 5) = ws2.Cells(j, 5)' in the second 'Do'-block in the code.
Does anybody have any idea what is wrong in that line? I would much appreciate any feedback.
Thanks, Chris
I have a list of names, some of which occur several times, with values attributed to the names in the adjacent column. I want a list in which the names occur once and the all the values belonging to the name appear in the row the name is in. I have code which almost does it, but not quite.
My data looks like this example:
fred 10
dave 1
jill 4
fred 11
marc 74
I want:
dave 1,
fred 10,11
jill 4,
marc 74,
so I start with a list
dave
fred
jill
marc
and then run my code.
My code is:
Option Explicit
Sub Compare()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim i As Long, j As Long, LR As Long
Set ws1 = Sheets("Deutsch")
Set ws2 = Sheets("Deutsch2")
For j = 2 To 182
i = 2
Do
If ws1.Cells(i, 5) = ws2.Cells(j, 5) Then
ws2.Cells(j, 6).Value = ws1.Cells(i, 6).Value
End If
i = i + 1
If i = 314 Then
Exit Do
End If
Loop Until ws2.Cells(j, 6) <> ""
Do
If ws1.Cells(i, 5) = ws2.Cells(j, 5) Then
ws2.Cells(j, 7).Value = ws1.Cells(i, 6).Value
End If
i = i + 1
If i = 314 Then
Exit Do
End If
Loop Until ws2.Cells(j, 7) <> ""
If i < 314 Then
Do
If ws1.Cells(i, 5) = ws2.Cells(j, 5) Then
ws2.Cells(j, 8).Value = ws1.Cells(i, 6).Value
End If
i = i + 1
If i = 314 Then
Exit Do
End If
Loop Until ws2.Cells(j, 8) <> ""
End If
Next j
End Sub
It works fine for a while, then gives me an 'error 1004 object or application error' at always the same point, when it gets to row 144 in the destination list.
The editor tells me I should debug the line 'If ws1.Cells(i, 5) = ws2.Cells(j, 5)' in the second 'Do'-block in the code.
Does anybody have any idea what is wrong in that line? I would much appreciate any feedback.
Thanks, Chris