VBA Add to Array and Use Previous Value
Posted
by
MattHead93
on Stack Overflow
See other posts from Stack Overflow
or by MattHead93
Published on 2013-07-03T10:56:21Z
Indexed on
2013/07/03
11:05 UTC
Read the original article
Hit count: 234
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!
© Stack Overflow or respective owner