Sheet1にSheet2にあって足らないデータを追記できるものを作っていますが、
Or以降のsh1.Cells(n, "A") = sh2.Cells(I, "A") And sh1.Cells(n, "L") <> sh2.Cells(I, "F")
の判定がうまくいきません。
A列で同じデータでも、もう一列で違うデータの場合には不足分とし追記できるようにしたいと考えています。
どこがいけないかわからないのでよろしくお願いします。
Sub 転記() Dim sh1 As Worksheet Dim sh2 As Worksheet Start = Time Set sh1 = Worksheets("Sheet1") Set sh2 = Worksheets("Sheet2") R1 = sh1.Cells(sh1.Rows.Count, "A").End(xlUp).row R2 = sh2.Cells(sh2.Rows.Count, "A").End(xlUp).row Application.ScreenUpdating = False Application.Calculation = xlCalculationManual n = R1 + 1 For I = 1 To R2 Set x = sh1.Range(sh1.Cells(1, "A"), sh1.Cells(R1, "A")).Find(What:=sh2.Cells(I, "A"), LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) If x Is Nothing And sh2.Cells(I, "AB") <> "" Or _ sh1.Cells(n, "A") = sh2.Cells(I, "A") And sh1.Cells(n, "L") <> sh2.Cells(I, "F") And sh2.Cells(I, "AB") <> "" Then sh1.Cells(n, "A") = sh2.Cells(I, "A") sh1.Cells(n, "B") = sh2.Cells(I, "B") n = n + 1 End If Next I Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True Finish = Time MsgBox "取得が完了しました" & vbLf & "実行時間は" & Format(Finish - Start, "nn分ss秒") & "でした" End Sub
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。