Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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?


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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?




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Loop to create Array davidm Excel Programming 4 June 15th 05 11:41 AM
how do I create an array lost Excel Discussion (Misc queries) 6 April 7th 05 12:43 AM
how do I create an array array_deficient Excel Discussion (Misc queries) 0 April 6th 05 09:53 PM
Create array function Yuriy Kuznetsov Excel Programming 2 November 2nd 04 03:05 PM
Create a PivotTable from a VBA array? Dave[_15_] Excel Programming 0 August 9th 03 12:58 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"