Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Insert into a range from a two dimensional array


Suppose I want to have cells A1 through B3 assigned the following
values:

2,4,8
2, 8,11

How do I create the right hand side of this statement?

Sub test()
Dim b As Workbook
Dim s As Worksheet
Set b = ThisWorkbook
Set s = b.Sheets("Sheet1")
s.Activate
Dim v
v = Array(2, 4, 8)
Dim s
s = Array(2,8,11)

'How to make v and s a two dimensional array?

Dim r As Range
Set r = s.Range(s.Cells(1, 1), s.Cells(2, 3))
r.Value = ??????? 'Assignment here wanted either in terms of v and
s or their 2 dimensional counterpart

End Sub

Don't bother posting a looping solution.

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Insert into a range from a two dimensional array

not sure, but this one fills the range from a 2D-array:

Public Sub Test()

Dim wb As Workbook
Dim sh As Worksheet

Dim v(0 To 3, 0 To 3) As Single
Dim r As Range
Dim e As Variant 'element in range
Dim c As Integer 'counter

Set wb = ThisWorkbook
Set sh = wb.Sheets("Sheet1")
Set r = sh.Range("A1:C2")
c = 1

v(1, 0) = 2
v(2, 0) = 4
v(3, 0) = 8

v(0, 1) = 2
v(0, 2) = 8
v(0, 3) = 11

'Looping solution...
For Each e In r

If c <= 3 Then
e.Value = v(c, 0)
ElseIf c 3 Then
e.Value = v(0, (c - 3))
End If
c = c + 1

Next

End Sub




schreef in bericht
oups.com...

Suppose I want to have cells A1 through B3 assigned the following
values:

2,4,8
2, 8,11

How do I create the right hand side of this statement?

Sub test()
Dim b As Workbook
Dim s As Worksheet
Set b = ThisWorkbook
Set s = b.Sheets("Sheet1")
s.Activate
Dim v
v = Array(2, 4, 8)
Dim s
s = Array(2,8,11)

'How to make v and s a two dimensional array?

Dim r As Range
Set r = s.Range(s.Cells(1, 1), s.Cells(2, 3))
r.Value = ??????? 'Assignment here wanted either in terms of v and
s or their 2 dimensional counterpart

End Sub

Don't bother posting a looping solution.

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Insert into a range from a two dimensional array

Not sure what exactly you are trying to do, but I don't think it is possible
to
populate a 2-D array from 1-D arrays without loops.
Possibly you could do it with the CopyMemory API, but not sure that is
worth the extra trouble.
What is wrong with using loops?

RBS

wrote in message
oups.com...

Suppose I want to have cells A1 through B3 assigned the following
values:

2,4,8
2, 8,11

How do I create the right hand side of this statement?

Sub test()
Dim b As Workbook
Dim s As Worksheet
Set b = ThisWorkbook
Set s = b.Sheets("Sheet1")
s.Activate
Dim v
v = Array(2, 4, 8)
Dim s
s = Array(2,8,11)

'How to make v and s a two dimensional array?

Dim r As Range
Set r = s.Range(s.Cells(1, 1), s.Cells(2, 3))
r.Value = ??????? 'Assignment here wanted either in terms of v and
s or their 2 dimensional counterpart

End Sub

Don't bother posting a looping solution.

Thanks.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Insert into a range from a two dimensional array

Thanks for spending the time getting that. But I need a solution that
DOES NOT USE LOOPING.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Insert into a range from a two dimensional array

The problem with loops is that they are way slow.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Insert into a range from a two dimensional array

On my machine this results in the string "2,4,8\n3,4,5" being inserted
into 4 cells.

Sub fillup()
Range("a2:b3").Value = "2,4,8" & vbCrLf & "3,4,5"
End Sub


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Insert into a range from a two dimensional array

If that is the problem then maybe post in the vb.winapi
group and I think it can be done with copymemory.

RBS

wrote in message
oups.com...
The problem with loops is that they are way slow.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Insert into a range from a two dimensional array

What do you think of this?


Sub fillup()
Dim b As Workbook
Dim s As Worksheet
Set b = ThisWorkbook
Set s = b.Sheets("Sheet1")
s.Range(s.Cells(1, 1), s.Cells(2, 3)).Value =
Evaluate("{2,4,8;3,4,5}")
End Sub

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Insert into a range from a two dimensional array

Unless it is a homework task then what is the point of the whole exercise?
If you are hard-coding your data then I can't see much use for it.

RBS

wrote in message
oups.com...
What do you think of this?


Sub fillup()
Dim b As Workbook
Dim s As Worksheet
Set b = ThisWorkbook
Set s = b.Sheets("Sheet1")
s.Range(s.Cells(1, 1), s.Cells(2, 3)).Value =
Evaluate("{2,4,8;3,4,5}")
End Sub




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Insert into a range from a two dimensional array

I don't know of a single college course where you can write VBA and
get credit for it.

I'm guessing you've never even been to college and here you are
trolling a Microsoft newsgroup..

Anyway read my google profile. I'm working on Perl/Applescript/Excel
stuff. Nothing you'd to in college.

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default Insert into a range from a two dimensional array

Range("a1:a3") = Application.Transpose(v)
Range("b1:b3") = Application.Transpose(s)

Alan Beban

wrote:
I don't know of a single college course where you can write VBA and
get credit for it.

I'm guessing you've never even been to college and here you are
trolling a Microsoft newsgroup..

Anyway read my google profile. I'm working on Perl/Applescript/Excel
stuff. Nothing you'd to in college.

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Insert into a range from a two dimensional array

Oh SWEET!

Thanks Alan.

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Insert into a range from a two dimensional array

I somehow thought you wanted to put 1-D arrays in a 2-D array.
Maybe you should learn to explain your questions a bit clearer.

RBS

wrote in message
ups.com...
I don't know of a single college course where you can write VBA and
get credit for it.

I'm guessing you've never even been to college and here you are
trolling a Microsoft newsgroup..

Anyway read my google profile. I'm working on Perl/Applescript/Excel
stuff. Nothing you'd to in college.


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
Returning an array from a multi-dimensional array Chris Excel Programming 2 January 3rd 07 06:01 AM
Load excel range into multi dimensional array Rishi Dhupar Excel Programming 1 January 26th 06 03:50 PM
Mutli-dimensional Array to Single-Dimension Array Blue Aardvark Excel Programming 3 October 15th 05 09:22 AM
Transferring part of a multi-dimensional array to a range in VBA Bob J.[_3_] Excel Programming 1 July 27th 05 03:38 PM
Create One-Dimensional Array from Two-Dimensional Array Stratuser Excel Programming 1 February 23rd 05 08:46 PM


All times are GMT +1. The time now is 07:57 AM.

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"