ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   create array (https://www.excelbanter.com/excel-programming/393273-create-array.html)

Al[_19_]

create array
 
There must be a better way of doing this....

Dim vv(10) As Integer
vv(1) = 1
vv(1) = 3
vv(1) = 4
vv(1) = 5
vv(1) = 7
vv(1) = 17
vv(1) = 18
vv(1) = 19
vv(1) = 20
vv(1) = 21
vv(1) = 22

Can't I do something like:
Dim vv(10)
vv() = (1,3,4,5,7,.....)

Al


Gary Keramidas

create array
 
maybe something like this?

Option Base 1
Sub test()
Dim vv As Variant
vv = Array(1, 3, 4, 5, 7, 17, 18, 19, 20, 21, 22)
MsgBox vv(1)
End Sub

--


Gary


"Al" wrote in message
oups.com...
There must be a better way of doing this....

Dim vv(10) As Integer
vv(1) = 1
vv(1) = 3
vv(1) = 4
vv(1) = 5
vv(1) = 7
vv(1) = 17
vv(1) = 18
vv(1) = 19
vv(1) = 20
vv(1) = 21
vv(1) = 22

Can't I do something like:
Dim vv(10)
vv() = (1,3,4,5,7,.....)

Al




Chip Pearson

create array
 
Al,

You could do something like

Dim N As Long
For N = LBound(vv) To UBound(vv)
vv(N) = N
Next N

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Al" wrote in message
oups.com...
There must be a better way of doing this....

Dim vv(10) As Integer
vv(1) = 1
vv(1) = 3
vv(1) = 4
vv(1) = 5
vv(1) = 7
vv(1) = 17
vv(1) = 18
vv(1) = 19
vv(1) = 20
vv(1) = 21
vv(1) = 22

Can't I do something like:
Dim vv(10)
vv() = (1,3,4,5,7,.....)

Al



Al[_19_]

create array
 
I'll try both, thanks.

Chip, how do I specify that N is to be the values I mentioned above,
considering they're not in sequence?


Chip Pearson

create array
 
I didn't notice that they were not sequential. Ignore my post and go with
Gary's.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Al" wrote in message
ups.com...
I'll try both, thanks.

Chip, how do I specify that N is to be the values I mentioned above,
considering they're not in sequence?



Tom Ogilvy

create array
 
I suspect that since your example assigned all the values to the same
element of the array, overwriting the previous assignment, Chip gave you a
generic approach.

Dim v as Variant
vv = Evaluate("{1,3,4,5,7,17,18,19,20,21,22}")


or building on Chips Example

Sub A()
Dim vv(0 To 10)
j = 0
For i = 1 To 7
If i < 2 And i < 6 Then
vv(j) = i
j = j + 1
End If
Next
For i = 17 To 22
vv(j) = i
j = j + 1
Next

For i = LBound(vv) To UBound(vv)
Debug.Print i, vv(i)
Next

End Sub

--
Regards,
Tom Ogilvy

"Al" wrote:

I'll try both, thanks.

Chip, how do I specify that N is to be the values I mentioned above,
considering they're not in sequence?



Dana DeLouis

create array
 
Sub A()
For i = 1 To 7
For i = 17 To 22


Given an Excel table, one of the programs I have gave the following 1-liner
as one of its suggestions:

Sub Demo()
Dim v
v = [Transpose(If(Row(1:11)<=5,Mod(1030, 6*Row(1:11)+1),11+Row(1:11)))]
End Sub

--
Dana DeLouis


"Tom Ogilvy" wrote in message
...
I suspect that since your example assigned all the values to the same
element of the array, overwriting the previous assignment, Chip gave you a
generic approach.

Dim v as Variant
vv = Evaluate("{1,3,4,5,7,17,18,19,20,21,22}")


or building on Chips Example

Sub A()
Dim vv(0 To 10)
j = 0
For i = 1 To 7
If i < 2 And i < 6 Then
vv(j) = i
j = j + 1
End If
Next
For i = 17 To 22
vv(j) = i
j = j + 1
Next

For i = LBound(vv) To UBound(vv)
Debug.Print i, vv(i)
Next

End Sub

--
Regards,
Tom Ogilvy

"Al" wrote:

I'll try both, thanks.

Chip, how do I specify that N is to be the values I mentioned above,
considering they're not in sequence?






All times are GMT +1. The time now is 05:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com