Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Using Loop to create Array | Excel Programming | |||
how do I create an array | Excel Discussion (Misc queries) | |||
how do I create an array | Excel Discussion (Misc queries) | |||
Create array function | Excel Programming | |||
Create a PivotTable from a VBA array? | Excel Programming |