Questa è la macro all'interno del file Calc
Codice: Seleziona tutto
REM Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Option Compatible
Dim importo(1 To 1000) As Double, quantita(1 To 1000) As Double, nummax As Integer, numaart As Integer, somma As Double
Sub estraisomma()
nummax = Cells(1, 19)
numart = Cells(2, 19)
For i = 1 To numart
quantita(i) = 0
importo(i) = 0
Next i
i = 1
While i <= nummax
If (IsNumeric(Cells(i, 2)) And Cells(i, 2) <> "") Then
j = Cells(i, 2)
End If
If (IsNumeric(Cells(i, 12)) And (IsNumeric(Cells(i, 14)) And Cells(i, 14) <> "")) Then
importo(j) = importo(j) + Cells(i, 16)
quantita(j) = quantita(j) + Cells(i, 12)
End If
i = i + 1
Wend
For i = 1 To numart
Cells(i, 20) = i
Cells(i, 21) = quantita(i)
Cells(i, 22) = Worksheets("Elenco prezzi").Cells(11 + i * 3 - 2, 6)
Cells(i, 23) = Cells(i, 21) * Cells(i, 22)
Cells(i, 24) = importo(i)
If Abs(Cells(i, 24) - Cells(i, 23)) > 1000 Then
Cells(i, 20).Select
Beep
MsgBox ("Errore")
End If
Next i
End Sub
Sub controllasomme()
nummax = Cells(1, 19)
numart = Cells(2, 19)
somma = 0
j = 0
i = 1
While i <= nummax
If (IsNumeric(Cells(i, 2)) And Cells(i, 2) <> "") Then
somma = 0
End If
If (Cells(i, 4) = "") And ((Cells(i, 6) = "") And (Cells(i, 8) = "") And (Cells(i, 10) = "") And (IsNumeric(Cells(i, 12)) And Cells(i, 12) <> "")) Then
Cells(i, 19) = somma
If (Abs(somma - Cells(i, 12)) > 0.005) And (somma <> 0) Then
Cells(i, 12).Select
Beep
MsgBox ("Errore di somma")
End If
End If
If (IsNumeric(Cells(i, 12)) And Cells(i, 12) <> "") Then
somma = somma + Cells(i, 12)
Cells(i, 12).Select
End If
i = i + 1
j = j + 1
Wend
End Sub
Sub controllaprodotti()
nummax = Cells(1, 19)
numart = Cells(2, 19)
i = 1
While i <= nummax
prodotto = 0
If (IsNumeric(Cells(i, 12)) And (Cells(i, 12) <> "")) Then
If (((IsNumeric(Cells(i, 4)) Or (Cells(i, 4) = ""))) And ((IsNumeric(Cells(i, 6)) Or (Cells(i, 6) = ""))) And ((IsNumeric(Cells(i, 8)) Or (Cells(i, 8) = "")) And (IsNumeric(Cells(i, 10)) Or (Cells(i, 10) = "")))) Then
Cells(i, 12).Select
If Cells(i, 4) <> "" Then a = Cells(i, 4) Else a = 1
If Cells(i, 6) <> "" Then b = Cells(i, 6) Else b = 1
If Cells(i, 8) <> "" Then c = Cells(i, 8) Else c = 1
If Cells(i, 10) <> "" Then d = Cells(i, 10) Else d = 1
prodotto = a * b * c * d
If (Abs(prodotto - Cells(i, 12)) > 0.005) And ((Cells(i, 4) <> "") Or (Cells(i, 6) <> "") Or (Cells(i, 8) <> "") Or (Cells(i, 10) <> "")) Then
Cells(i, 12).Select
Cells(i, 18) = prodotto
Beep
MsgBox ("Errore di prodotto")
End If
End If
End If
i = i + 1
Wend
End Sub