VBA Add to Array and Use Previous Value
- by MattHead93
I'm trying to write some code that will take a value WeekNum, and add it to an array Week(1 To 51), and then associate a value from a Textbox TargDef.
Once this has been added to the array, I want to look up the value of the array for the previous WeekNum and add it to a value ProdTarg.
I've created this much so far:
Dim Week(1 To 51)
Dim Count As Integer
If TargDef < 0 Then
Count = WeekNum
Week(Count) = Abs(Val(TargDef))
If Val(Week((Count) - 1)) = 0 Then
ProdTarg = Val(ProdTarg)
Else
ProdTard = Val(ProdTarg) + Val(Week((Count) - 1))
End If
End If
I am currently receiving the error "Subscript out of Range" for the line If Val(Week((Count) - 1)) = 0 Then
Any help will be greatly appreciated!