View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Robert ap Rhys Robert ap Rhys is offline
external usenet poster
 
Posts: 21
Default How to insert array into range


"Gary''s Student" wrote in message
...
Sub Macro1()
Dim s(10, 10) As String
For i = 1 To 10
For j = 1 To 10
Cells(i, j).Value = s(i, j)
Next
Next
End Sub


Hi Gary,

It much easier, and a whole lot faster to create a reference to a range
object with the same dimensions as the array, and then use the Value
property:

Private Sub Test()
Dim str(1 To 7, 1 To 2) As String
Dim i As Integer
For i = 1 To 7
str(i, 1) = Format(i, "dddd")
str(i, 2) = Format(i * 29, "mmmm")
Next
With ThisWorkbook.Worksheets(1)
.Range(.Cells(14, 3), _
.Cells(14 + 6, 3 + 1)).Value = str
End With
End Sub

The OP will have to translate to VB.NET - the range reference and the
dimensions of the array (all arrays are zero based in .NET).

Robert