Dim UC As Integer, UR As Long, RR As Long, I As Long, J As Long, K As Long, Trovato As Integer
Dim Ws1 As Worksheet, Ws2 As Worksheet
Dim Matrice1(), Inizio As Double, Sostituiti As Long, Ricalcolo As Variant
Inizio = Timer
Ricalcolo = Application.Calculation
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set Ws1 = Sheets("BE_Fatt")
Set Ws2 = Sheets("Dati_Importati")
UR = Ws2.Range("A" & Rows.Count).End(xlUp).Row
UC = Ws1.Range(Ws1.Cells(1, Columns.Count).Address).End(xlToLeft).Column
Matrice1 = Ws2.Range(Ws2.Cells(1, 1), Ws2.Cells(UR, 3))
Sostituiti = 0
UR = Ws1.Range("L" & Rows.Count).End(xlUp).Row
UC = Ws1.Range(Ws1.Cells(1, Columns.Count).Address).End(xlToLeft).Column
For I = 2 To UBound(Matrice1)
If Application.WorksheetFunction.CountIf(Ws1.Range("M100:M" & UR), Matrice1(I, 2)) > 0 Then
For J = 100 To UR
ProgressBar.Show
If Ws1.Cells(J, "M") = Matrice1(I, 2) Then
For K = 14 To UC
If Ws1.Cells(5, K) = Matrice1(I, 1) Then
Ws1.Cells(J, K) = Matrice1(I, 3)
Sostituiti = Sostituiti + 1
Exit For
End If
Next K
Exit For
End If
Next J
End If
Next I
Application.ScreenUpdating = True
Application.Calculation = Ricalcolo
If Sostituiti > 0 Then
MsgBox "Elaborazione effettuata. " & vbCrLf & vbCrLf & "Sostituiti: " & Sostituiti & " dati in '" & Format(Timer - Inizio, "0.00") & "' Secondi"
Else
MsgBox "Non sono stati trovati dati da sostituire", vbCritical
End If
Set Ws1 = Nothing
Set Ws2 = Nothing
Application.ScreenUpdating = True |