PC Review


Reply
Thread Tools Rate Thread

Assign a 2D array of constant values to a range

 
 
dodgo
Guest
Posts: n/a
 
      17th Oct 2006
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 With Quote
 
 
 
 
=?Utf-8?B?Sk1C?=
Guest
Posts: n/a
 
      17th Oct 2006
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.
>
>

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      17th Oct 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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 With Quote
 
=?Utf-8?B?Sk1C?=
Guest
Posts: n/a
 
      17th Oct 2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >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 With Quote
 
dodgo
Guest
Posts: n/a
 
      19th Oct 2006
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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference array constant values in a formula notso Microsoft Excel Misc 2 28th Sep 2008 11:34 PM
Assign Values to array Jeff Microsoft Excel Misc 14 15th Jul 2008 06:06 PM
Can't assign values to array Buddy Ackerman Microsoft Dot NET 6 19th Dec 2004 10:50 PM
Can't assign values to array Buddy Ackerman Microsoft ASP .NET 6 19th Dec 2004 10:50 PM
How do I assign values to an array? Skyway Microsoft Excel Programming 14 29th Feb 2004 01:22 AM


Features
 

Advertising
 

Newsgroups
 


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