sd1fa53s4fa5s65d
New Member
- Joined
- Feb 20, 2015
- Messages
- 2
Moshi Moshi
I am very new to excel. I learned it because I suddenly was given a large amount of data to organize. Unfortunately, I cannot figure out a way to make the code below run without crashing after spitting out a few solutions. By "crashing" I mean I am forced to restart Excel and VBA because both programs stops responding. I do not know why it is crashing, but I am thinking it is because I vba cannot process the task I am giving it.
I am able to complete what I want to accomplish by manually changing numbers in each "For" loop. If I were to allow all loops to run, the program will crash.
Any feedback will be helpful.
Happy Friday
Sub Multiply()
'Total
Dim C, B As Integer
'COMBINED Row Number
Dim X As Integer
X = 2
'Months
For Q = 1 To 12
If Q = 1 Then
P = 39
ElseIf Q = 3 Then
P = 39
ElseIf Q = 5 Then
P = 39
ElseIf Q = 7 Then
P = 39
ElseIf Q = 8 Then
P = 39
ElseIf Q = 10 Then
P = 39
ElseIf Q = 12 Then
P = 39
ElseIf Q = 2 Then
P = 36
Else: P = 38
End If
'however long the rows are in each MONTH
For A = 8 To P
'Sheet 13 loop for 105 times
For Y = 2 To 105
'Add up one total in each month
For Z = 7 To 1600
'Finding Totals for each item
If Sheets(13).Cells(Y, 1) = Sheets(Q).Cells(Z, 6) Then
B = Sheets(Q).Cells(Z, A) * Sheets(Q).Cells(Z, 5)
Else: B = 0
End If
'Add Totals
C = C + B
Next Z
'Prints Totals
Sheets(13).Cells(Y, X) = C
'Refresh Totals
C = 0
Next Y
X = X + 1
Next A
Next Q
End Sub
I am very new to excel. I learned it because I suddenly was given a large amount of data to organize. Unfortunately, I cannot figure out a way to make the code below run without crashing after spitting out a few solutions. By "crashing" I mean I am forced to restart Excel and VBA because both programs stops responding. I do not know why it is crashing, but I am thinking it is because I vba cannot process the task I am giving it.
I am able to complete what I want to accomplish by manually changing numbers in each "For" loop. If I were to allow all loops to run, the program will crash.
Any feedback will be helpful.
Happy Friday
Sub Multiply()
'Total
Dim C, B As Integer
'COMBINED Row Number
Dim X As Integer
X = 2
'Months
For Q = 1 To 12
If Q = 1 Then
P = 39
ElseIf Q = 3 Then
P = 39
ElseIf Q = 5 Then
P = 39
ElseIf Q = 7 Then
P = 39
ElseIf Q = 8 Then
P = 39
ElseIf Q = 10 Then
P = 39
ElseIf Q = 12 Then
P = 39
ElseIf Q = 2 Then
P = 36
Else: P = 38
End If
'however long the rows are in each MONTH
For A = 8 To P
'Sheet 13 loop for 105 times
For Y = 2 To 105
'Add up one total in each month
For Z = 7 To 1600
'Finding Totals for each item
If Sheets(13).Cells(Y, 1) = Sheets(Q).Cells(Z, 6) Then
B = Sheets(Q).Cells(Z, A) * Sheets(Q).Cells(Z, 5)
Else: B = 0
End If
'Add Totals
C = C + B
Next Z
'Prints Totals
Sheets(13).Cells(Y, X) = C
'Refresh Totals
C = 0
Next Y
X = X + 1
Next A
Next Q
End Sub