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.
|