ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying a Variant Array to a worksheet (https://www.excelbanter.com/excel-programming/344692-copying-variant-array-worksheet.html)

John Keith[_2_]

Copying a Variant Array to a worksheet
 
What is the short-hand method to copy a varaint array to a worksheet.

Given a variant array called vaData which is 10 rows x 5 columns

Range("F20:I26").Value = vaData 'Would copy the data to F20:I26

How can this be written dynamically using
Ubound(vaData) and UBound(vaData,2) in place of the cell range reference?

--
Regards,
John

RB Smissaert

Copying a Variant Array to a worksheet
 
If the array is a 2-D 1-based array all will be the same as the range as
this Sub shows:

Sub test()

Dim arr

arr = Range(Cells(1), Cells(10, 10))

Range(Cells(LBound(arr), LBound(arr, 2)), Cells(UBound(arr), UBound(arr,
2))) = arr

End Sub


RBS


"John Keith" wrote in message
...
What is the short-hand method to copy a varaint array to a worksheet.

Given a variant array called vaData which is 10 rows x 5 columns

Range("F20:I26").Value = vaData 'Would copy the data to F20:I26

How can this be written dynamically using
Ubound(vaData) and UBound(vaData,2) in place of the cell range reference?

--
Regards,
John



John Keith[_2_]

Copying a Variant Array to a worksheet
 
Just answered my own question...
Addr = "$F$20"
Addr = Addr & ":" & Range(Addr).Cells(UBound(vaData), _
UBound(vaData, 2)).Address
Range(Addr).Value = vaData

--
Regards,
John


"John Keith" wrote:

What is the short-hand method to copy a varaint array to a worksheet.

Given a variant array called vaData which is 10 rows x 5 columns

Range("F20:I26").Value = vaData 'Would copy the data to F20:I26

How can this be written dynamically using
Ubound(vaData) and UBound(vaData,2) in place of the cell range reference?

--
Regards,
John



All times are GMT +1. The time now is 12:25 AM.

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