View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default How to return Array() to range as variable?

Hi

The rng is implicit declared as a Variant, so the array is just
assigned to the rng variable.

To make the it work declare rng as Range, or use rng.Value=Array(...).
Using both will also work.

Sub testit()
Dim rng as Range
Set rng = Range("b2:d2")
rng.Value = Array(21, 22, 23)
End Sub

Hopes this helps.

---
Per

On 6 Maj, 22:14, "JoeU2004" wrote:
The following does what I want:

Sub testit()
Range("b2:d2") = Array(21, 22, 23)
End Sub

But I would prefer to use a variable instead of Range("b2:d2"). *(Part of a
larger macro.)

Why doesn't the following work? *More importantly, how can I make it work?

Sub testit()
Dim rng
Set rng = Range("b2:d2")
rng = Array(21, 22, 23)
End Sub