Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Copying array into disjoint range.

Seems like I alway have trouble when dealing with disjoint ranges.

This time I'm trying to do a simple copy of a matrix (2-D array) into a
disjoint range.
The dimensions of the disjoint range and the array are the same, but I get
gobbledygook (without pattern) when I do the assignment.
The first line actually copies fine, but then the other lines that are
disjoint from the first, won't work.

Dim matrix As Variant
'code to fill matrix
Range("testrange") = matrix

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying array into disjoint range.

I am not 100% sure what you mean by "disjoint range" or "the dimensions of
the disjoint range and the array are the same", but my guess is you have a
normal contiguous range that you refer to as "matrix" and a "disjoint" range
with the same number of rows as the matrix has, but which are not
necessarily adjacent to each other, but each of its rows has the same number
of columns and that number is the same as the number of columns in the
matrix. If that is the case, give this code a try...

Sub CopyMatrixToDisjointRows()
Dim R As Range
Dim MatrixRange As Range
Dim CopyToRange As Range
Dim RowIndex As Long
Set MatrixRange = Range("C3:F7")
Set CopyToRange = Range("J8:M8,M10:P10,B15:E15,D20:G20")
RowIndex = 1
For Each R In CopyToRange.Rows
MatrixRange.Rows(RowIndex).Copy R
RowIndex = RowIndex + 1
Next
End Sub

Rick


"Lance Roberts" <LJRoberts(at)gvea.com wrote in message
...
Seems like I alway have trouble when dealing with disjoint ranges.

This time I'm trying to do a simple copy of a matrix (2-D array) into a
disjoint range.
The dimensions of the disjoint range and the array are the same, but I get
gobbledygook (without pattern) when I do the assignment.
The first line actually copies fine, but then the other lines that are
disjoint from the first, won't work.

Dim matrix As Variant
'code to fill matrix
Range("testrange") = matrix

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Copying array into disjoint range.

Rick,

You've got most of it.
The big difference is that my matrix is a Variant Array object (filled by a
Recordset Getrows method).
I don't know of a Rows method for the array, but the documentation is very
sparse on multidimensional arrays in VBA, so if you know of any way to
extract rows or columns, that'd be great.
I've been searching for literal days on the web to uncover a helpful syntax.

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.


"Rick Rothstein (MVP - VB)" wrote:

I am not 100% sure what you mean by "disjoint range" or "the dimensions of
the disjoint range and the array are the same", but my guess is you have a
normal contiguous range that you refer to as "matrix" and a "disjoint" range
with the same number of rows as the matrix has, but which are not
necessarily adjacent to each other, but each of its rows has the same number
of columns and that number is the same as the number of columns in the
matrix. If that is the case, give this code a try...

Sub CopyMatrixToDisjointRows()
Dim R As Range
Dim MatrixRange As Range
Dim CopyToRange As Range
Dim RowIndex As Long
Set MatrixRange = Range("C3:F7")
Set CopyToRange = Range("J8:M8,M10:P10,B15:E15,D20:G20")
RowIndex = 1
For Each R In CopyToRange.Rows
MatrixRange.Rows(RowIndex).Copy R
RowIndex = RowIndex + 1
Next
End Sub

Rick


"Lance Roberts" <LJRoberts(at)gvea.com wrote in message
...
Seems like I alway have trouble when dealing with disjoint ranges.

This time I'm trying to do a simple copy of a matrix (2-D array) into a
disjoint range.
The dimensions of the disjoint range and the array are the same, but I get
gobbledygook (without pattern) when I do the assignment.
The first line actually copies fine, but then the other lines that are
disjoint from the first, won't work.

Dim matrix As Variant
'code to fill matrix
Range("testrange") = matrix

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Copying array into disjoint range.

Lance Roberts wrote:
Rick,

You've got most of it.
The big difference is that my matrix is a Variant Array object (filled by a
Recordset Getrows method).
I don't know of a Rows method for the array, but the documentation is very
sparse on multidimensional arrays in VBA, so if you know of any way to
extract rows or columns, that'd be great.
I've been searching for literal days on the web to uncover a helpful syntax.


Application.Index(myArray,n,0), where myArray is a 2-D array, will
return the nth row.

Alan Beban
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying array into disjoint range.

I have virtually no experience with databases, so I'll be fumbling around
here a little bit. When you say "Variant Array object (filled by a Recordset
Getrows method)", are you talking about an ADO or DAO record set object? If
so, the Range object has a CopyFromRecordset Method which might prove
useful. If you have such a record set object, let's call it RS, then I think
you might be able to modify my original code like this (remember, I am
guessing here)...

Sub CopyMatrixToDisjointRows()
Dim R As Range
Dim MatrixRange As Range
Dim CopyToRange As Range
Dim RowIndex As Long
Dim RS As Recordset
'
' Obtain your RS Recordset here
'
MatrixRange.CopyFromRecordset RS
Set CopyToRange = Range("J8:M8,M10:P10,B15:E15,D20:G20")
RowIndex = 1
For Each R In CopyToRange.Rows
MatrixRange.Rows(RowIndex).Copy R
RowIndex = RowIndex + 1
Next
End Sub

Obviously, if this works, you will need to adjust the Range you are setting
the CopyToRange range to to match your actual addresses.

Rick


"Lance Roberts" <LJRoberts(at)gvea.com wrote in message
...
Rick,

You've got most of it.
The big difference is that my matrix is a Variant Array object (filled by
a
Recordset Getrows method).
I don't know of a Rows method for the array, but the documentation is very
sparse on multidimensional arrays in VBA, so if you know of any way to
extract rows or columns, that'd be great.
I've been searching for literal days on the web to uncover a helpful
syntax.

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.


"Rick Rothstein (MVP - VB)" wrote:

I am not 100% sure what you mean by "disjoint range" or "the dimensions
of
the disjoint range and the array are the same", but my guess is you have
a
normal contiguous range that you refer to as "matrix" and a "disjoint"
range
with the same number of rows as the matrix has, but which are not
necessarily adjacent to each other, but each of its rows has the same
number
of columns and that number is the same as the number of columns in the
matrix. If that is the case, give this code a try...

Sub CopyMatrixToDisjointRows()
Dim R As Range
Dim MatrixRange As Range
Dim CopyToRange As Range
Dim RowIndex As Long
Set MatrixRange = Range("C3:F7")
Set CopyToRange = Range("J8:M8,M10:P10,B15:E15,D20:G20")
RowIndex = 1
For Each R In CopyToRange.Rows
MatrixRange.Rows(RowIndex).Copy R
RowIndex = RowIndex + 1
Next
End Sub

Rick


"Lance Roberts" <LJRoberts(at)gvea.com wrote in message
...
Seems like I alway have trouble when dealing with disjoint ranges.

This time I'm trying to do a simple copy of a matrix (2-D array) into a
disjoint range.
The dimensions of the disjoint range and the array are the same, but I
get
gobbledygook (without pattern) when I do the assignment.
The first line actually copies fine, but then the other lines that are
disjoint from the first, won't work.

Dim matrix As Variant
'code to fill matrix
Range("testrange") = matrix

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Copying array into disjoint range.

Whoooooppppppiiiiiieeeee!

I've looked through hundreds of pages in help files, books and the web, and
that was EXACTLY what I needed. I only had to move the array to a 1-based
array and it worked great. Thanks for all the help.

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.


"Alan Beban" wrote:

Lance Roberts wrote:
Rick,

You've got most of it.
The big difference is that my matrix is a Variant Array object (filled by a
Recordset Getrows method).
I don't know of a Rows method for the array, but the documentation is very
sparse on multidimensional arrays in VBA, so if you know of any way to
extract rows or columns, that'd be great.
I've been searching for literal days on the web to uncover a helpful syntax.


Application.Index(myArray,n,0), where myArray is a 2-D array, will
return the nth row.

Alan Beban

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Copying array into disjoint range.

Rick,

If I could copy directly into the range, that would work great,
but I have to manipulate the data first.

Also, in regards to my last reply, you only have to massage the row index in
the Index function, i.e. array row 0 will be accessed with a value 1, the
function doesn't use the array index values but absolute addressing on the
array.

My final code:

For i = 0 To 10
Range("TSR_" & i) =
Application.WorksheetFunction.Index(prelimmatrix, i + 1, 0)
Next i

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.


"Rick Rothstein (MVP - VB)" wrote:

I have virtually no experience with databases, so I'll be fumbling around
here a little bit. When you say "Variant Array object (filled by a Recordset
Getrows method)", are you talking about an ADO or DAO record set object? If
so, the Range object has a CopyFromRecordset Method which might prove
useful. If you have such a record set object, let's call it RS, then I think
you might be able to modify my original code like this (remember, I am
guessing here)...

Sub CopyMatrixToDisjointRows()
Dim R As Range
Dim MatrixRange As Range
Dim CopyToRange As Range
Dim RowIndex As Long
Dim RS As Recordset
'
' Obtain your RS Recordset here
'
MatrixRange.CopyFromRecordset RS
Set CopyToRange = Range("J8:M8,M10:P10,B15:E15,D20:G20")
RowIndex = 1
For Each R In CopyToRange.Rows
MatrixRange.Rows(RowIndex).Copy R
RowIndex = RowIndex + 1
Next
End Sub

Obviously, if this works, you will need to adjust the Range you are setting
the CopyToRange range to to match your actual addresses.

Rick


"Lance Roberts" <LJRoberts(at)gvea.com wrote in message
...
Rick,

You've got most of it.
The big difference is that my matrix is a Variant Array object (filled by
a
Recordset Getrows method).
I don't know of a Rows method for the array, but the documentation is very
sparse on multidimensional arrays in VBA, so if you know of any way to
extract rows or columns, that'd be great.
I've been searching for literal days on the web to uncover a helpful
syntax.

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.


"Rick Rothstein (MVP - VB)" wrote:

I am not 100% sure what you mean by "disjoint range" or "the dimensions
of
the disjoint range and the array are the same", but my guess is you have
a
normal contiguous range that you refer to as "matrix" and a "disjoint"
range
with the same number of rows as the matrix has, but which are not
necessarily adjacent to each other, but each of its rows has the same
number
of columns and that number is the same as the number of columns in the
matrix. If that is the case, give this code a try...

Sub CopyMatrixToDisjointRows()
Dim R As Range
Dim MatrixRange As Range
Dim CopyToRange As Range
Dim RowIndex As Long
Set MatrixRange = Range("C3:F7")
Set CopyToRange = Range("J8:M8,M10:P10,B15:E15,D20:G20")
RowIndex = 1
For Each R In CopyToRange.Rows
MatrixRange.Rows(RowIndex).Copy R
RowIndex = RowIndex + 1
Next
End Sub

Rick


"Lance Roberts" <LJRoberts(at)gvea.com wrote in message
...
Seems like I alway have trouble when dealing with disjoint ranges.

This time I'm trying to do a simple copy of a matrix (2-D array) into a
disjoint range.
The dimensions of the disjoint range and the array are the same, but I
get
gobbledygook (without pattern) when I do the assignment.
The first line actually copies fine, but then the other lines that are
disjoint from the first, won't work.

Dim matrix As Variant
'code to fill matrix
Range("testrange") = matrix

--
Lance Roberts
Control Systems Engineer
Golden Valley Electric Assoc.




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
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R[_2_] Excel Programming 3 November 13th 07 04:08 PM
Last Row in Disjoint Range Scott Excel Programming 2 December 20th 06 05:42 AM
Disjoint range for DSUM criteria Jim Bennett Excel Worksheet Functions 2 June 9th 05 03:50 AM
Copying array formula to a range of cells... Dennis G. Excel Programming 7 January 4th 05 09:43 PM
Quick way of copying Range to (sub)Array ? John Mitchell Excel Programming 2 September 16th 04 03:43 AM


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