ブック内の2枚のシートを3枚比較し、3枚の列がすべて一致したら、 (列G)から2番目のシートの列Pに移動する。 私は以下のコードを使用しようとしていますが、動作するようには思えない。(空白を返します)事前にあなたの助けを2枚目の3列を比較すると、1枚目の4列目の値が2枚目と一致する場合
Sub CopyCells()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim j As Long, i As Long, lastrow1 As Long, lastrow2 As Long
Set sh1 = Worksheets("EOD")
Set sh2 = Worksheets("Consolidated")
lastrow1 = sh1.Cells(Rows.Count, "A").End(xlUp).Row
lastrow2 = sh2.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow1
For j = 2 To lastrow2
If sh1.Cells(i, "A").Value = sh2.Cells(j, "B").Value And _
sh1.Cells(i, "B").Value = sh2.Cells(j, "C").Value And _
sh1.Cells(i, "C").Value = sh2.Cells(j, "D").Value Then
sh1.Cells(i, "G").Value = sh2.Cells(j, "P").Value
End If
Next j
Next i
End Sub
感謝を!
私は100%わからないんだけど、それはあなたが秒に1枚目の値をコピーしている方法のように思えますシートのP列のシートが間違っている場合は、sh2.cells(j、 "P")。value = sh1.cells(i、 "G")としてください。値 – Xabier
こんにちは、Xabier.Iさんに感謝しました。空白を得る。 –