Ranges and Arrays - Passing values

  • Thread starter Thread starter Don Lloyd
  • Start date Start date
D

Don Lloyd

Hi,

I can populate an array from a range quite easily, e.g.

Dim TestArray as Variant
TestArray = Range("C5").CurrentRegion.Value

Is there a way to pass values back to the range in a similar fashion ?
That is, without referring to the individual Array and Cell co-ordinates.

regards,
Don
 
Hi again,

Sorry to have bothered you but Problem solved. e.g.

Range("C5:F13").Value = TestArray

Thanks and regards,
Don
 
Just to mention an idea. With the use of "CurrentRegion," your array size
is unknown. However, the output range (C5:F13) is "hard coded." See if
you could use this general idea.

Sub Demo()
Dim TestArray
TestArray = Range("C5").CurrentRegion.Value
'// Your code here...then

Range("C5").Resize _
(UBound(TestArray, 1), UBound(TestArray, 2)) = TestArray
End Sub

HTH
 
Dana said:
Just to mention an idea. With the use of "CurrentRegion," your array size
is unknown. However, the output range (C5:F13) is "hard coded." See if
you could use this general idea.

Sub Demo()
Dim TestArray
TestArray = Range("C5").CurrentRegion.Value
'// Your code here...then

Range("C5").Resize _
(UBound(TestArray, 1), UBound(TestArray, 2)) = TestArray
End Sub

HTH
Or if TestArray might be (or have been changed by your code to) a
0-based array, substitute

Range("C5").Resize(UBound(TestArray,1)-LBound(TestArray,1)+1, _
UBound(TestArray,2)-LBound(TestArray,2)+1) = TestArray

Alan Beban
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top