Option Explicit
Sub carica()
Dim sh1 As Worksheet: Set sh1 = Worksheets("PRODUZIONE") ' da cambiare casomai
Dim sh2 As Worksheet: Set sh2 = Worksheets("IMBALLAGGIO") ' da cambiare casomai
Dim sh3 As Worksheet: Set sh3 = Worksheets("Riepilogo") ' da cambiare casomai
Dim Ur1, Ur2, Ur3, X, R, Rg As Object
Ur1 = sh1.Range("E" & Rows.Count).End(xlUp).Row
Ur2 = sh2.Range("E" & Rows.Count).End(xlUp).Row
Ur3 = sh3.Range("I" & Rows.Count).End(xlUp).Row
If Ur3 < 4 Then Ur3 = 4
Application.EnableEvents = False
For X = 4 To Ur1
Set Rg = sh3.Range(sh3.Cells(4, 9), sh3.Cells(Ur3, 9)).Find(sh1.Cells(X, 5), LookIn:=xlValues, LookAt:=xlWhole)
If Rg Is Nothing Then
R = Ur3 + 1
Ur3 = Ur3 + 1
sh3.Cells(R, 9) = sh1.Cells(X, 5) 'esempio sh3.Cells(R, 1) = sh1.Cells(X, 1)
'ex sh3.Cells(R, 1) cella di destinazione sul foglio riepilogo (colonna A)
'segue = sh1.Cells(X, 1)cella del foglio di produzione dove prende il dato (colonna A)
'qui sopra metti tutte le celle che vuoi copiare, modifica solo il numero
Else
R = Rg.Row
sh3.Cells(R, 9) = sh1.Cells(X, 5) 'esempio
'qui sopra metti tutte le celle che vuoi copiare, modifica solo il numero
End If
Next X
For X = 4 To Ur2
Set Rg = sh3.Range(sh3.Cells(4, 9), sh3.Cells(Ur3, 9)).Find(sh2.Cells(X, 5), LookIn:=xlValues, LookAt:=xlWhole)
If Rg Is Nothing Then
R = Ur3 + 1
Ur3 = Ur3 + 1
sh3.Cells(R, 9) = sh2.Cells(X, 5) 'esempio sh3.Cells(R, 1) = sh1.Cells(X, 1)
'ex sh3.Cells(R, 1) cella di destinazione sul foglio riepilogo (colonna A)
'segue = sh1.Cells(X, 1)cella del foglio di imballaggio dove prende il dato (colonna A)
'qui sopra metti tutte le celle che vuoi copiare, modifica solo il numero
Else
R = Rg.Row
sh3.Cells(R, 9) = sh2.Cells(X, 5) 'esempio
'qui sopra metti tutte le celle che vuoi copiare, modifica solo il numero
End If
Next X
Application.EnableEvents = True
Set sh1 = Nothing
Set sh2 = Nothing
Set sh3 = Nothing
MsgBox "fatto"
End Sub |