ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Array Population with a Single Line of Code (https://www.excelbanter.com/excel-programming/290449-vba-array-population-single-line-code.html)

James B

VBA Array Population with a Single Line of Code
 
I'm trying to figure out how to populate an array variable
in VBA without using something similar to the code below:

ReDim a(1 To 4)
a(1) = 2
a(2) = 3
a(3) = 5
a(4) = 7

Can this be done with a single line of code? Also, can I
populate a single section of a multidimensional array with
something like the following?

beta(7,3 to 14)= ..... the values for those points in the
array

Any help is certainly appreciated. I've been doing this
the long way for years, and it is driving me crazy!

Bob Phillips[_6_]

VBA Array Population with a Single Line of Code
 
Hi James,

Single dimension

Dim a

a = Array(2,3,5,7)

Multi-dimension

Dim beta

beta = [{7,3;8,4;9,5;10,6;11,7;12,8;13,9;14,10}]

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"James B" wrote in message
...
I'm trying to figure out how to populate an array variable
in VBA without using something similar to the code below:

ReDim a(1 To 4)
a(1) = 2
a(2) = 3
a(3) = 5
a(4) = 7

Can this be done with a single line of code? Also, can I
populate a single section of a multidimensional array with
something like the following?

beta(7,3 to 14)= ..... the values for those points in the
array

Any help is certainly appreciated. I've been doing this
the long way for years, and it is driving me crazy!




Alan Beban[_4_]

VBA Array Population with a Single Line of Code
 
As for your first question

Option Base 1
___________________
Sub junk()
Dim a()
a=Array(2,3,5,7)
End Sub

As for your second, with the functions in the freelydownloadable file at
http://home.pacbell.net/beban available to your workbook

Option Base 1
___________________
Sub junk2()
Dim beta, arr
beta = Range("a1:p13")
arr = Array(103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114)
ReplaceSubArray beta, arr, 7, 3
End Sub

Simply, replace that portion of beta beginning at row index 7, column
index 3 with the elements of arr.

Alan Beban

James B wrote:
I'm trying to figure out how to populate an array variable
in VBA without using something similar to the code below:

ReDim a(1 To 4)
a(1) = 2
a(2) = 3
a(3) = 5
a(4) = 7

Can this be done with a single line of code? Also, can I
populate a single section of a multidimensional array with
something like the following?

beta(7,3 to 14)= ..... the values for those points in the
array

Any help is certainly appreciated. I've been doing this
the long way for years, and it is driving me crazy!



Alan Beban[_4_]

VBA Array Population with a Single Line of Code
 
Reading Bob Phillips's response made it clear that there is some
ambiguity in what you requested in your second inquiry. I assumed that
you had a 2-D array variable, beta, and you wanted to repopulate row 7,
column 3 to 14, with the unspecified list of values. In any event,
that's what my last post assumed.

Alan Beban

James B wrote:
I'm trying to figure out how to populate an array variable
in VBA without using something similar to the code below:

ReDim a(1 To 4)
a(1) = 2
a(2) = 3
a(3) = 5
a(4) = 7

Can this be done with a single line of code? Also, can I
populate a single section of a multidimensional array with
something like the following?

beta(7,3 to 14)= ..... the values for those points in the
array

Any help is certainly appreciated. I've been doing this
the long way for years, and it is driving me crazy!



No Name

VBA Array Population with a Single Line of Code
 
Thanks, Alan.

These VBA functions should add a lot of firepower to the
array manipulation I've been working on (reservoir
simulation).

- James

-----Original Message-----
As for your first question

Option Base 1
___________________
Sub junk()
Dim a()
a=Array(2,3,5,7)
End Sub

As for your second, with the functions in the

freelydownloadable file at
http://home.pacbell.net/beban available to your workbook

Option Base 1
___________________
Sub junk2()
Dim beta, arr
beta = Range("a1:p13")
arr = Array(103, 104, 105, 106, 107, 108, 109, 110, 111,

112, 113, 114)
ReplaceSubArray beta, arr, 7, 3
End Sub

Simply, replace that portion of beta beginning at row

index 7, column
index 3 with the elements of arr.

Alan Beban

James B wrote:
I'm trying to figure out how to populate an array

variable
in VBA without using something similar to the code

below:

ReDim a(1 To 4)
a(1) = 2
a(2) = 3
a(3) = 5
a(4) = 7

Can this be done with a single line of code? Also, can

I
populate a single section of a multidimensional array

with
something like the following?

beta(7,3 to 14)= ..... the values for those points in

the
array

Any help is certainly appreciated. I've been doing

this
the long way for years, and it is driving me crazy!


.


No Name

VBA Array Population with a Single Line of Code
 
Thanks, Bob.

I'll now be able to quickly load in a multidimensional
array and then shift or paste it as needed via Alan's
toolkit.

- James


-----Original Message-----
Hi James,

Single dimension

Dim a

a = Array(2,3,5,7)

Multi-dimension

Dim beta

beta = [{7,3;8,4;9,5;10,6;11,7;12,8;13,9;14,10}]

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"James B" wrote in

message
...
I'm trying to figure out how to populate an array

variable
in VBA without using something similar to the code

below:

ReDim a(1 To 4)
a(1) = 2
a(2) = 3
a(3) = 5
a(4) = 7

Can this be done with a single line of code? Also, can

I
populate a single section of a multidimensional array

with
something like the following?

beta(7,3 to 14)= ..... the values for those points in

the
array

Any help is certainly appreciated. I've been doing this
the long way for years, and it is driving me crazy!



.


Tom Ogilvy

VBA Array Population with a Single Line of Code
 
Don't get too excited. <g This is extremely limited as to the number of
elements you can load.

--
Regards,
Tom Ogilvy

wrote in message
...
Thanks, Bob.

I'll now be able to quickly load in a multidimensional
array and then shift or paste it as needed via Alan's
toolkit.

- James


-----Original Message-----
Hi James,

Single dimension

Dim a

a = Array(2,3,5,7)

Multi-dimension

Dim beta

beta = [{7,3;8,4;9,5;10,6;11,7;12,8;13,9;14,10}]

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"James B" wrote in

message
...
I'm trying to figure out how to populate an array

variable
in VBA without using something similar to the code

below:

ReDim a(1 To 4)
a(1) = 2
a(2) = 3
a(3) = 5
a(4) = 7

Can this be done with a single line of code? Also, can

I
populate a single section of a multidimensional array

with
something like the following?

beta(7,3 to 14)= ..... the values for those points in

the
array

Any help is certainly appreciated. I've been doing this
the long way for years, and it is driving me crazy!



.




Bob Phillips[_6_]

VBA Array Population with a Single Line of Code
 
James,

Curious, what is reservoir simulation?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

wrote in message
...
Thanks, Alan.

These VBA functions should add a lot of firepower to the
array manipulation I've been working on (reservoir
simulation).

- James





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

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