前回の続きです。
前回のコードの後にコピー&ペーストしてください。
For i = 2 To wS2.Cells(Rows.Count, 1).End(xlUp).Row
.Range("A1").AutoFilter field:=1, Criteria1:=wS2.Cells(i, 1)
.Range("A1").AutoFilter field:=2, Criteria1:=wS2.Cells(i, 2)
lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
Range(.Cells(2, 1), .Cells(lastRow, 16)).Copy wS3.Cells(1, 1)
For k = 1 To wS3.Cells(Rows.Count, 1).End(xlUp).Row
If InStr(wS2.Cells(i, 3), wS3.Cells(k, 3)) = 0 Then
wS2.Cells(i, 3) = wS2.Cells(i, 3) & "," & wS3.Cells(k, 3)
End If
If InStr(wS2.Cells(i, 4), wS3.Cells(k, 4)) = 0 Then
wS2.Cells(i, 4) = wS2.Cells(i, 4) & "," & wS3.Cells(k, 4)
End If
If InStr(wS2.Cells(i, 5), wS3.Cells(k, 5)) = 0 Then
wS2.Cells(i, 5) = wS2.Cells(i, 5) & "," & wS3.Cells(k, 5)
End If
If InStr(wS2.Cells(i, 6), wS3.Cells(k, 6)) = 0 Then
wS2.Cells(i, 6) = wS2.Cells(i, 6) & "," & wS3.Cells(k, 6)
End If
If InStr(wS2.Cells(i, 7), wS3.Cells(k, 7)) = 0 Then
wS2.Cells(i, 7) = wS2.Cells(i, 7) & "," & wS3.Cells(k, 7)
End If
If InStr(wS2.Cells(i, 7), wS3.Cells(k, 8)) = 0 Then
wS2.Cells(i, 7) = wS2.Cells(i, 7) & "," & wS3.Cells(k, 8)
End If
If InStr(wS2.Cells(i, 8), wS3.Cells(k, 9)) = 0 Then
wS2.Cells(i, 8) = wS2.Cells(i, 8) & "," & wS3.Cells(k, 9)
End If
If InStr(wS2.Cells(i, 8), wS3.Cells(k, 10)) = 0 Then
wS2.Cells(i, 8) = wS2.Cells(i, 8) & "," & wS3.Cells(k, 10)
End If
If InStr(wS2.Cells(i, 9), wS3.Cells(k, 11)) = 0 Then
wS2.Cells(i, 9) = wS2.Cells(i, 9) & "," & wS3.Cells(k, 11)
End If
If InStr(wS2.Cells(i, 9), wS3.Cells(k, 12)) = 0 Then
wS2.Cells(i, 9) = wS2.Cells(i, 9) & "," & wS3.Cells(k, 12)
End If
If InStr(wS2.Cells(i, 10), wS3.Cells(k, 13)) = 0 Then
wS2.Cells(i, 10) = wS2.Cells(i, 10) & "," & wS3.Cells(k, 13)
End If
If InStr(wS2.Cells(i, 10), wS3.Cells(k, 14)) = 0 Then
wS2.Cells(i, 10) = wS2.Cells(i, 10) & "," & wS3.Cells(k, 14)
End If
If InStr(wS2.Cells(i, 11), wS3.Cells(k, 15)) = 0 Then
wS2.Cells(i, 11) = wS2.Cells(i, 11) & "," & wS3.Cells(k, 15)
End If
If InStr(wS2.Cells(i, 11), wS3.Cells(k, 16)) = 0 Then
wS2.Cells(i, 11) = wS2.Cells(i, 11) & "," & wS3.Cells(k, 16)
End If
Next k
wS3.Cells.Clear
Next i
.AutoFilterMode = False
wS2.Columns.AutoFit
wS2.Range("A1").CurrentRegion.Borders.LineStyle = xlContinuous
End With
Application.ScreenUpdating = True
End Sub
こんな感じではどうでしょうか?m(_ _)m
お礼
間違えてました。シートのコードに貼り付けてやってしまっていました。ちゃんと動くきました。 ありがとうございます!!
補足
このコードで実行してみました。 すると「実行時エラー’1004': アプリケーション定義またはオブジェクト定義のエラーです。」 とでました。