gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,347
- Office Version
- 365
- Platform
- Windows
Can anyone explain this error to me?
I called out where the error is down below
I called out where the error is down below
Code:
Sub Distribute()
Sheets("DM Material Distribution").Activate
Columns("J:MK").Select
Selection.Delete Shift:=xlToLeft
Range("I4").Select
Range(Cells(3, 10), Cells(1000, 1000)).ClearContents
Dim min As Date
Dim no_of_months As Integer
no_of_months = Cells(2, 9)
min = Cells(2, 7)
Cells(3, 10) = no_of_months
'***************************
'Add Months starting in 3, 10
For i = 0 To (no_of_months - 1)
Cells(3, 10 + i) = DateAdd("m", i, min)
Next
Dim Spread_amount As Integer
Dim no_of_item_months As Integer
For x = 4 To Cells(2, 6)
curve = Left(Cells(x, 5), 2)
If curve = "EV" Then
no_of_item_months = DateDiff("m", Cells(x, 7), Cells(x, 8)) + 1
start_date_col = DateDiff("m", min, Cells(x, 7))
For t = 1 To no_of_item_months
Cells(x, t + start_date_col + 9) = Application.WorksheetFunction.RoundDown((Cells(x, 9) / no_of_item_months), 0)
Next
diff = Cells(x, 9) - Cells(x, start_date_col + 10) * no_of_item_months
For i = 1 To diff
Cells(x, i + start_date_col + 9) = Cells(x, i + start_date_col + 9) + 1
Next
ElseIf curve = "(N" Or curve = "Lo" Then
'**********************************************************************************************
'ERRORS ON THE "start_date_col = DateDiff("m", min, Cells(x, 7))"
'**********************************************************************************************
Else:
start_date_col = DateDiff("m", min, Cells(x, 7))
Worksheets(curve).Cells(1, 1) = Cells(x, 9)
no_of_item_months = DateDiff("m", Cells(x, 7), Cells(x, 8)) + 1
Cells(1, 1) = no_of_item_months
Worksheets(curve).Cells(3, 7) = no_of_item_months
Dim steps As Integer
Worksheets(curve).Cells(1, 2) = "Hello"
Range(Worksheets(curve).Cells(4, 7), Worksheets(curve).Cells(1000, 7)).ClearContents
Range(Worksheets(curve).Cells(4, 8), Worksheets(curve).Cells(1000, 8)).ClearContents
Range(Worksheets(curve).Cells(4, 9), Worksheets(curve).Cells(1000, 9)).ClearContents
steps = Worksheets(curve).Cells(3, 7)
For i = 1 To steps
j = (i - 1) * 12 / (steps - 1) + (steps - i) / (steps - 1)
Worksheets(curve).Cells(3 + i, 7) = j
Worksheets(curve).Cells(4, 5) = j
Worksheets(curve).Cells(i + 3, 8) = Worksheets(curve).Cells(4, 6)
Next
Sum_all = Application.WorksheetFunction.Sum(Range(Worksheets(curve).Cells(4, 8), Worksheets(curve).Cells(1000, 8)))
For i = 1 To steps
Worksheets(curve).Cells(i + 3, 9) = Application.WorksheetFunction.Round(Worksheets(curve).Cells(i + 3, 8) / Sum_all * Worksheets(curve).Cells(1, 1), 0)
Next
Max = Worksheets(curve).Cells(1, 11)
dif = Worksheets(curve).Cells(2, 11)
Worksheets(curve).Cells(Max, 9) = Worksheets(curve).Cells(Max, 9) - dif
start_date_col = DateDiff("m", min, Cells(x, 7))
Cells(2, 1) = start_date_col
For g = 0 To no_of_item_months - 1
Cells(x, 10 + start_date_col + g) = Worksheets(curve).Cells(g + 4, 9)
Next
Cells(1, 1) = curve
End If
Next
End Sub