m5u4r3p2h1y
New Member
- Joined
- May 8, 2013
- Messages
- 14
Hi,
I,m trying to allow a user to input a year (between 2004-2012), each of which will be stored into an array. Since I don't know how many years the user will choose I'm required to use a dynamic array. For some reason when I run the code below it takes a valid input but then exits the loop instead of asking for another. I have the message boxes at the bottom to verify the array is getting the values, but they all return the value 0. If anyone could help I'd appreciate it.
Thanks.
Sub DataRange()
Dim Message, Title, DefaultValue As String
Dim RangeBoxArray() As Long
Dim i As Integer
Message = "Enter the years you would like to study (2004-2012 one year at a time). Click OK with value=0 to finish."
Title = "Historical Load Data Range"
DefaultValue = 0
i = 1
ReDim RangeBoxArray(i)
Do
RangeBoxArray(i) = InputBox(Message, Title, DefaultValue, 100, 100)
i = i + 1
ReDim RangeBoxArray(i)
Loop Until RangeBoxArray(i - 1) > 2013 Or RangeBoxArray(i - 1) < 2003
MsgBox RangeBoxArray(0)
MsgBox RangeBoxArray(1)
MsgBox RangeBoxArray(2)
End Sub
I,m trying to allow a user to input a year (between 2004-2012), each of which will be stored into an array. Since I don't know how many years the user will choose I'm required to use a dynamic array. For some reason when I run the code below it takes a valid input but then exits the loop instead of asking for another. I have the message boxes at the bottom to verify the array is getting the values, but they all return the value 0. If anyone could help I'd appreciate it.
Thanks.
Sub DataRange()
Dim Message, Title, DefaultValue As String
Dim RangeBoxArray() As Long
Dim i As Integer
Message = "Enter the years you would like to study (2004-2012 one year at a time). Click OK with value=0 to finish."
Title = "Historical Load Data Range"
DefaultValue = 0
i = 1
ReDim RangeBoxArray(i)
Do
RangeBoxArray(i) = InputBox(Message, Title, DefaultValue, 100, 100)
i = i + 1
ReDim RangeBoxArray(i)
Loop Until RangeBoxArray(i - 1) > 2013 Or RangeBoxArray(i - 1) < 2003
MsgBox RangeBoxArray(0)
MsgBox RangeBoxArray(1)
MsgBox RangeBoxArray(2)
End Sub