Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Assign a 2D array of constant values to a range

I thought I'd done this in the past, but I can't remember if or how. I
want be able to assign an array of values to a range in 1 go, such as

1 2 3
4 5 6
7 8 9

to A1:C3

I'd thought I'd done something like Range("A1:C3") =
(1,2,3;4,5,6;7,8,9)
using ; as a delimiter between rows in the array, but that clearly
isn't working.

I'm quite familiar with the looping/iterator techniques available to
assign a variable array to a range. I was just hoping there was a way
to do this in one line of code.

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Assign a 2D array of constant values to a range

You can use array constants in Excel formulae, but I don't think VBA has
multidimensional array constants. You should be able to assign your data to
a 2 dimensional array variable and set your range equal to that

Range("A1:C3").Value = arrData

where arrData is a 3x3 array.


"dodgo" wrote:

I thought I'd done this in the past, but I can't remember if or how. I
want be able to assign an array of values to a range in 1 go, such as

1 2 3
4 5 6
7 8 9

to A1:C3

I'd thought I'd done something like Range("A1:C3") =
(1,2,3;4,5,6;7,8,9)
using ; as a delimiter between rows in the array, but that clearly
isn't working.

I'm quite familiar with the looping/iterator techniques available to
assign a variable array to a range. I was just hoping there was a way
to do this in one line of code.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assign a 2D array of constant values to a range

Sub AABB()
Range("A1:C3").Value = _
Evaluate("{1,2,3;4,5,6;7,8,9}")

End Sub

works for small amounts of data.

--
Regards,
Tom Ogilvy


"dodgo" wrote in message
oups.com...
I thought I'd done this in the past, but I can't remember if or how. I
want be able to assign an array of values to a range in 1 go, such as

1 2 3
4 5 6
7 8 9

to A1:C3

I'd thought I'd done something like Range("A1:C3") =
(1,2,3;4,5,6;7,8,9)
using ; as a delimiter between rows in the array, but that clearly
isn't working.

I'm quite familiar with the looping/iterator techniques available to
assign a variable array to a range. I was just hoping there was a way
to do this in one line of code.



  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Assign a 2D array of constant values to a range

I always overlook the the opportunities to use Evaluate. Thanks Tom.

"Tom Ogilvy" wrote:

Sub AABB()
Range("A1:C3").Value = _
Evaluate("{1,2,3;4,5,6;7,8,9}")

End Sub

works for small amounts of data.

--
Regards,
Tom Ogilvy


"dodgo" wrote in message
oups.com...
I thought I'd done this in the past, but I can't remember if or how. I
want be able to assign an array of values to a range in 1 go, such as

1 2 3
4 5 6
7 8 9

to A1:C3

I'd thought I'd done something like Range("A1:C3") =
(1,2,3;4,5,6;7,8,9)
using ; as a delimiter between rows in the array, but that clearly
isn't working.

I'm quite familiar with the looping/iterator techniques available to
assign a variable array to a range. I was just hoping there was a way
to do this in one line of code.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Assign a 2D array of constant values to a range

Thanks guys, I'll need to read up on evaluate to understand what its
capable of altogether.

In hindsight, I believe I was remembering about creating 2D arrays in
formulas in spreadsheets, using the format shown within the quotation
marks.

JMB wrote:
I always overlook the the opportunities to use Evaluate. Thanks Tom.

"Tom Ogilvy" wrote:

Sub AABB()
Range("A1:C3").Value = _
Evaluate("{1,2,3;4,5,6;7,8,9}")

End Sub

works for small amounts of data.

--
Regards,
Tom Ogilvy


"dodgo" wrote in message
oups.com...
I thought I'd done this in the past, but I can't remember if or how. I
want be able to assign an array of values to a range in 1 go, such as

1 2 3
4 5 6
7 8 9

to A1:C3

I'd thought I'd done something like Range("A1:C3") =
(1,2,3;4,5,6;7,8,9)
using ; as a delimiter between rows in the array, but that clearly
isn't working.

I'm quite familiar with the looping/iterator techniques available to
assign a variable array to a range. I was just hoping there was a way
to do this in one line of code.







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
Reference array constant values in a formula notso Excel Discussion (Misc queries) 2 September 28th 08 11:34 PM
Assign Values to array Jeff Excel Discussion (Misc queries) 14 July 15th 08 06:06 PM
Excel 2003. Assign array to range Jorge Vinuales Excel Programming 2 May 2nd 06 06:06 PM
HOW TO ASSIGN 2 DIMENSION ARRAY VALUES FROM 2 COLUMNS? -JEFF-[_2_] Excel Programming 3 August 12th 05 05:36 PM
How do I assign values to an array? Skyway[_2_] Excel Programming 14 February 29th 04 01:22 AM


All times are GMT +1. The time now is 06:15 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"