ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copy matrix to worksheet (https://www.excelbanter.com/excel-programming/423970-copy-matrix-worksheet.html)

MÃ¥ns TÃ¥nneryd

copy matrix to worksheet
 
Hi!

I have a two-dimensionnal matrix and i would like copy the contents of this
matrix directly to the cells in a worksheet without iterating over each cell
one by one. Is this possible? Anyone out there that knows?

Thanks!

/MÃ¥ns TÃ¥nneryd

Chip Pearson

copy matrix to worksheet
 

If by "matrix" you mean a range of cells on a worksheet, you can use
code like the following:

Dim Matrix As Range
Dim Dest As Range
Set Matrix = Range("B4:C7") '<<< CHANGE AS REQUIRED
Set Dest = Range("F10") '<<< CHANGE AS REQUIRED
Matrix.Copy Destination:=Dest

This copies the range B4:C7 to a range starting at F10.


If by "matrix" you mean a 2 dimensional array, you can use code like
the following:

Dim Matrix(1 To 2, 1 To 2) As Long
Dim R As Long
Dim C As Long
' load up test values
Matrix(1, 1) = 11
Matrix(1, 2) = 22
Matrix(2, 1) = 33
Matrix(2, 2) = 44
' get number of rows and columns
R = UBound(Matrix, 1) - LBound(Matrix, 1) + 1
C = UBound(Matrix, 2) - LBound(Matrix, 2) + 1
' resize the destination range
Range("F10").Resize(R, C).Value = Matrix


This writes the contents of the Matrix array to cell F10.



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 12 Feb 2009 06:40:16 -0800, Måns Tånneryd
wrote:

Hi!

I have a two-dimensionnal matrix and i would like copy the contents of this
matrix directly to the cells in a worksheet without iterating over each cell
one by one. Is this possible? Anyone out there that knows?

Thanks!

/Måns Tånneryd



All times are GMT +1. The time now is 10:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com