I want to create a function MyRange as follows:
Input: three numbers a,b,d
Output: an array of values from a to b with step size of d.
For example, if A1 contains 1, and B1 contains 5, and you write =MyRange(A1,B1,1) in the cell C1 (and you type Ctrl+Shift+Enter) you get:
A | B | C | D | E | F | G
-------------------------
1 | 5 | 1 | 2 | 3 | 4 | 5
Here's my trial:
Function MyRange(a, b, d)
Dim Index As Integer, Number As Integer
Dim Res() As Integer
Index = 0
For Number = a To b Step d
Res(Index) = Number
Index = Index + 1
Next Number
MyRange = Res
End Function
When I try this, Excel throws #VALUE! and I don't know what's the problem..
BTW yeah, I had a similar question before that got no answer, as it was too complicated, so I'd deleted it and simplified my question here.
C1:C[B+2]
and enter the array formula with all these columns highlighted to get your output.