Good night, i'm writing a code to sort some values into a new worksheet but i keep gettiong the "runtime Error 9, subscript out of range. I dont know exactly how to check it but I think it must be the c6 counter...
What I'm trying to do, is to add to the Cell number the value of the counter, but now all it does is to give me that runtime error...
Before, I wrote this code but i think i is full of errors of the sum i would like to do:
The last one runs but i get some mistakes in the sum...
The first one tries to be an update of the last one but it has the runtime error...
Thanks
Code:
Sub MacroAnaliticw1()
Application.Calculation = xlManual
Application.ScreenUpdating = False
'inicializacion
Dim c1 As Integer, c2 As Integer, c3 As Integer, c4 As Integer, c5 As Integer, c6 As Integer, c7 As Integer
Dim SKU(1 To 35) As Long, store(1 To 163) As Integer, suma(1 To 5705) As
' c# are counters, skus are product numbers
'Here i wrote a long list of the SKU of the products and the store values
'I'm doing a sum of 4 diferent sheets and getting the sum value.
'I'm doing the
For c1 = 1 To 4
Sheets(c1).Activate
For c2 = 1 To 4
c6 = 0
If Cells(c2, 4).Value = "SKU" Then
For c3 = 1 To 10000
c5 = 0
If SKU(1) = Cells(c2 + c3, 4).Value Or SKU(2) = Cells(c2 + c3, 4).Value _
Or SKU(3) = Cells(c2 + c3, 4).Value Then
For c4 = 1 To 163
If store(c4) = Cells(c2 + c3 + c4, 7).Value Then
suma(c6 + c4) = suma(c6 + c4) + Cells(c2 + c3 + c4, 15).Value
c5 = c5 + 1
c6 = c6 + 1
End If
Next c4
End If
c3 = c3 + c5
If c3 > 10000 Then
c3 = 10000
End If
Next c3
End If
Next c2
Next c1
DoEvents
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
End Sub
Before, I wrote this code but i think i is full of errors of the sum i would like to do:
Code:
´same initialization values as before, only that this was my last code;
'Hacer Suma
For c1 = 1 To 4
Sheets(c1).Activate
For c2 = 1 To 4
c6 = 0
If Cells(c2, 4).Value = "SKU" Then
For c3 = 1 To 10000
c5 = 0
If SKU(1) = Cells(c2 + c3, 4).Value Or SKU(2) = Cells(c2 + c3, 4).Value _
Or SKU(3) = Cells(c2 + c3, 4).Value Then
For c4 = 1 To 163
If tienda(c4) = Cells(c2 + c3 + c4, 7).Value Then
suma(c6 + c4) = suma(c6 + c4) + Cells(c2 + c3 + c4, 15).Value
c5 = c5 + 1
c6 = c6 + 1
End If
Next c4
End If
c3 = c3 + c5
If c3 > 10000 Then
c3 = 10000
End If
Next c3
End If
Next c2
Next c1
DoEvents
The first one tries to be an update of the last one but it has the runtime error...
Thanks