|
▼tantan さん:
>Sheet1とSheet2のJ3セル以下の製造番号を対比して同じであれば
>Sheet2のFG列より右に入っている数字やテキストなどすべてをSheet1の
>同じ場所にコピーしたい
こんにちは。
こんな感じですか。
Sub TESTa()
' Sheet2 --> Sheet1
Dim v1 As Variant
Dim v2 As Variant
Dim v3 As Variant
Dim Dic As Object
Dim i As Long
Dim j As Long
With Worksheets("Sheet2")
v1 = .Range("J3:J" & .Range("J" & .Rows.Count).End(xlUp).Row).Value
v2 = .Range("FG3:IV" & .Range("J" & .Rows.Count).End(xlUp).Row).Value
End With
Set Dic = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(v1)
If Not Dic.Exists(v1(i, 1)) Then
Dic(v1(i, 1)) = i
End If
Next
With Worksheets("Sheet1")
v1 = .Range("J3:J" & .Range("J" & .Rows.Count).End(xlUp).Row).Value
v3 = .Range("FG3:IV" & .Range("J" & .Rows.Count).End(xlUp).Row).Value
End With
For i = 1 To UBound(v1)
If Dic.Exists(v1(i, 1)) Then
For j = 1 To UBound(v2, 2)
v3(i, j) = v2(Dic(v1(i, 1)), j)
Next
End If
Next
With Worksheets("Sheet1")
.Range("FG3").Resize(UBound(v3), UBound(v3, 2)).Value = v3
End With
End Sub
|
|