Good night, I keep getting a runtime error in my code, could anyone tell me why is it? It's a code for a database:
Thanks
Code:
Sub MacroParrilla()
Application.Calculation = xlManual
Dim c1 As Integer, c2 As Integer, c3 As Integer, cposible As Integer, ctotal As Integer, SKU As Integer, c As Integer
Dim c4 As Integer, c5 As Integer, c6 As Integer, c7 As Integer, c8 As Integer, suma(1 To 162) As Integer, c9 As Integer
For c9 = 1 To 162
suma(c9) = 0
Next c9
'For that looks up for SKU
For c = 1 To 2
Sheets(c).Activate
For c1 = 1 To 1500
For c2 = 1 To 60
If Cells(c1, c2).Value = "SKU" Then
SKU = Cells(c1, c2 + 1).Value
For c6 = 1 To 8
Sheets(c6).Activate
For c3 = 1 To 1500
For c4 = 1 To 60
If Cells(c1, c2).Value = SKU Then
For c5 = 3 To 164
suma(c5 - 2) = suma(c5 - 2) + Cells(c1 + c5, c2 + 1).Value
Next c5
End If
Next c4
Next c3
Next c6
Sheets(c).Activate
For c5 = 3 To 164
suma(c5 - 2) = suma(c5 - 2) - Cells(c1 + c5, c2).Value
If suma(c5 - 2) < 1 Then
Cells(c1 + c5, c2).Value = 0
Else
'Sku individual
If SKU = 235990 Or SKU = 244772 Or SKU = 950541 Or SKU = 950558 Or SKU = 950800 Or _
SKU = 2394244 Or SKU = 2394053 Or SKU = 3276556 Or SKU = 3276549 Then
Cells(c1 + c5, c2).Value = suma(c5 - 2)
'sku w/3
ElseIf SKU = 3141182 Or SKU = 3141175 Or SKU = 3141151 Or SKU = 3141113 Then
cposible = suma(c5 - 2) / 3
cposible = cposible * 3
cposible = suma(c5 - 2) - cposible
If cposible > 2 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(c1 + c5, c2 + 2).Value = ctotal
'SKU w/4
ElseIf SKU = 950732 Or SKU = 4546887 Or SKU = 4546849 Or SKU = 4546832 Then
cposible = suma(c5 - 2) / 4
cposible = cposible * 4
cposible = suma(c5 - 2) - cposible
If cposible > 2 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(c1 + c5, c2 + 2).Value = ctotal
'SKU w/5
ElseIf SKU = 3113141 Or SKU = 2974743 Or SKU = 244681 Or SKU = 244665 Or SKU = 244657 Or SKU = 244640 Then
cposible = suma(c5 - 2) / 5
cposible = cposible * 5
cposible = suma(c5 - 2) - cposible
If cposible > 3 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(c1 + c5, c2 + 2).Value = ctotal
'SKU w/10
ElseIf SKU = 244616 Then
cposible = suma(c5 - 2) / 10
cposible = cposible * 10
cposible = suma(c5 - 2) - cposible
If cposible > 5 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(c1 + c5, c2 + 2).Value = ctotal
'SKU w/15
ElseIf SKU = 950435 Or SKU = 950442 Or SKU = 2393995 Or SKU = 2394022 Or SKU = 2394060 Or SKU = 2394008 _
Or SKU = 2395197 Or SKU = 2394077 Or SKU = 950459 Or SKU = 950466 Or SKU = 2393988 Or _
SKU = 2394084 Or SKU = 2394039 Or SKU = 2394015 Or SKU = 2394046 Or SKU = 2394091 Or _
SKU = 2394107 Or SKU = 2394114 Or SKU = 2394121 Or SKU = 2394138 Or SKU = 2394152 _
Or SKU = 2394169 Or SKU = 2394183 Or SKU = 2394190 Or SKU = 2394213 Or SKU = 2394220 _
Or SKU = 2394329 Or SKU = 2394237 Or SKU = 2394251 Or SKU = 2394282 Or SKU = 2394299 _
Or SKU = 2394305 Or SKU = 2394336 Or SKU = 2394350 Or SKU = 2394367 Then
cposible = suma(c5 - 2) / 15
cposible = cposible * 15
cposible = suma(c5 - 2) - cposible
If cposible > 8 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(c1 + c5, c2 + 2).Value = ctotal
'SKU w/25
ElseIf SKU = 1133561 Or SKU = 1133578 Or SKU = 1133585 Then
cposible = suma(c5 - 2) / 25
cposible = cposible * 25
cposible = suma(c5 - 2) - cposible
If cposible > 13 Then
ctotal = ctotal + cposible
Else
ctotal = ctotal - cposible
End If
Cells(c1 + c5, c2 + 2).Value = ctotal
End If
End If
Next c5
For c9 = 1 To 162
suma(c9) = 0
Next c9
End If
Next c2
Next c1
Next c
Application.Calculation = xlAutomatic
End Sub
Thanks