i keep gettiong the "runtime Error 9, subscript out of range...

Santino_X

New Member
Joined
May 1, 2011
Messages
15
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...

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
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:
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 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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I keep getting the error whenever i try to move the c6 = c6 + 1 after the End If before the Next c4
Although it should be after the end if so it adds 1 all the time instead of only adding if it enters the for cycle...
 
Upvote 0
I keep getting the error whenever i try to move the c6 = c6 + 1 after the End If before the Next c4
Although it should be after the end if so it adds 1 all the time instead of only adding if it enters the for cycle...

This doesn't help much. Please post the entire code that errors and colour the line red where it debugs out. This makes it much easier for those of us reading to understand what is going wrong and suggest solutions.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top