I want to create a list of numbers using an array, but I don't want the last number to be known, instead it's dependent on other factors, for example you ask a user what the top limit is, and the array will stop there.
I created an array that will produce a list of numbers, but when the end number is known for example:
Sub makearray50() 'creates a list of numbers from 1 to 50
Dim i As Integer
Dim theArray(1 To 50) As Double
For i = 1 To 50
theArray(i) = Int(0 + i)
Next i
For i = 1 To 50
Sheets("ARRAY").Cells(i, 1).Value = theArray(i)
Next i
End Sub
So I thought I would try with an unknown upper limit, this was what I tried:
Sub makearrayx() 'creates a list of numbers from 1 to x
Dim i As Integer
Dim x As Integer
x = 10
Dim theArray(1 To x) As Double
For i = 1 To x
theArray(i) = Int(0 + i)
Next i
For i = 1 To x
Sheets("ARRAY").Cells(i, 1).Value = theArray(i)
Next i
End Sub
I thought by trying with x "known" I could then edit it and ask the user what they would like x to be (using an input box) but VBA won't allow it, I get the error message:
ReDim Preserveto keep the array as you add to it.Here's an SO thread on it, and the Microsoft page. Also, how'd you code the input box? They should be able to be used.Int(0 + i)wheniis already an integer?0to the number? What's your thinking there?