Sub Correggi_errori()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Dim aW As Range
Dim bW As Range
Dim cW As Range
Dim dW As Range
Dim eW As Range
Dim bbW As Range
Dim aaW As Range
Dim i As Long
Dim erre As Integer
Set aW = Sheets("Parametri").Range("A7:A2705")
Set bW = Sheets("Parametri").Range("B7:B2705")
Set cW = Sheets("Parametri").Range("C7:C2705")
Set dW = Sheets("Parametri").Range("D7:D2705")
Set eW = Sheets("Parametri").Range("E7:E2705")
Set bbW = Sheets("Impianto Base").Range("B7:B2705")
Set aaW = Sheets("Parametri").Range("C3")
erre = 0
aW.FormulaR1C1 = "=MID(Imp_Base[@LOTTO],1,1)"
On Error Resume Next
Sheets("Impianto Base").Activate
For i = 7 To 2705
If Sheets("Impianto Base").Cells(i, "B").Value = 1 And Sheets("Impianto Base").Range("M" & i) = "NON IN GIACENZA" Then
Sheets("Impianto Base").Range("F" & i & ":H" & i).ClearContents
End If
If Sheets("Impianto Base").Cells(i, "B").Value = 1 And Sheets("Impianto Base").Range("M" & i) <> "NON IN GIACENZA" And Sheets("Impianto Base").Range("N" & i) = 1 And Sheets("Parametri").Range("A" & i) <> 0 Then
Sheets("Impianto Base").Range("F" & i & ":H" & i).ClearContents
Sheets("Impianto Base").Range("O" & i & ":P" & i).Copy
Sheets("Impianto Base").Range("F" & i).PasteSpecial xlPasteValues
Sheets("Impianto Base").Range("H" & i) = 1
End If
If Sheets("Impianto Base").Cells(i, "B").Value = 1 And Sheets("Impianto Base").Range("M" & i) <> "OK" And Sheets("Impianto Base").Range("M" & i) <> "NON IN GIACENZA" And Sheets("Parametri").Range("A" & i) = 0 Then
erre = erre + 1
End If
If Sheets("Impianto Base").Cells(i, "B").Value = 1 And Sheets("Impianto Base").Range("M" & i) <> "OK" And Sheets("Impianto Base").Range("M" & i) <> "NON IN GIACENZA" And Sheets("Impianto Base").Range("N" & i) > 1 Then
erre = erre + 1
End If
Next
aW.ClearContents
Sheets("Impianto Base").Activate
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
If erre + erre > 0 Then
If MsgBox("Ci sono " & erre & " referenze con errori che non è stato possibile correggere e altre " & Sheets("Parametri").Range("I2").Value - erre & " righe con errori che non erano selezionate. Vuoi selezionarle tutte ?", vbYesNo, "Operazione Completata") = vbYes Then
Application.ScreenUpdating = False
bbW.ClearContents
Sheets("Parametri").Activate
aW.FormulaR1C1 = _
"=IF(Imp_Base[@INVENTARIO]=""OK"",""0"",""1"")"
bW.FormulaR1C1 = _
"=IF(Imp_Base[@INVENTARIO]=""IN SCADENZA"",""0"",""1"")"
cW.FormulaR1C1 = "=RC[-2]+RC[-1]+RC[+1]"
dW.FormulaR1C1 = _
"=IF(AND(Imp_Base[@INVENTARIO]=""NON IN GIACENZA"",Imp_Base[@QTA]<0.5),-1,0)"
eW.FormulaR1C1 = _
"=IF(RC[-2]<2,"""",1)"
eW.Copy
bbW.PasteSpecial xlPasteValues
Range(aW, eW).ClearContents
Application.CutCopyMode = False
Sheets("Impianto Base").Activate
Range("N2").Select
dimmi = MsgBox("Ok, ho selezionato le referenze con errori.", vbInformation, "Operazione Completata")
End If
Exit Sub
Else
dimmi = MsgBox("Tutte le righe selezionate sono state corrette.", vbInformation, "Operazione Completata")
End If
Application.ScreenUpdating = True
End Sub
|