Quick way to populate cells from arrays ?
I have half a dozen arrays that populate a sheet.
At the mo I am populating the sheet in the worst (slowest) possible way, i.e. using acivecell.offset and then moving down a line and repeating etc.
Theres a much better way to do this .. but I can't remember it.
Can anyone remind me ?
Ta :)
Re: Quick way to populate cells from arrays ?
You can copy the whole array to a range of the same dimensions.
Here's a simple example
VB Code:
Sub CopyArrayDemo()
Dim aMyData()
Dim x, y
ReDim aMyData(1 To 5, 1 To 2)
For x = 1 To 5
For y = 1 To 2
aMyData(x, y) = x * y * 10
Next y
Next x
ThisWorkbook.Worksheets(1).Range("A1:B5").Value = aMyData
End Sub
Re: Quick way to populate cells from arrays ?
Thats a good idea .. although 2 elements of the array I have to check and do a "If this value then do this else do this" scenario, so I'm not sure if that scuppers things.
I'll have a play around and see what I can come up with.
Cheers Kenny !
Re: Quick way to populate cells from arrays ?
I can't recall if I did this and got it working, but if your range is of one cell I think you can paste in an single array of values horizontally.
something like:
Code:
set rng = sht.cells(1,1)
rng=ary()