LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Range to Array

Thanks to all of you.
Just another Dim mistake.

(or was I being Dim witted??)
--
Gary''s Student - gsnu200727


"Peter T" wrote:

In your second example you are trying to assign a single value to an
undimensioned variant array, it will fail.
Declare ' v ' without the brackets, then it can accept either a single value
or an array of values. You could test IsArray(v) or r.count 1.

If you need ' v ' to be a 2d array for consistency you could do this
(untested)

Sub qwerty3()
Dim r As Range
Dim v() ' redundant
Set r = Range("A1:g2")
With r
ReDim v(1 To .Rows.Count, 1 To .Columns.Count)
End With
If r.Count = 1 Then
v(1, 1) = r.Value
Else
v = r.Value
End If

Debug.Print UBound(v), UBound(v, 2)
End Sub

Regards,
Peter T

"Gary''s Student" wrote in message
...
Why does:

Sub qwerty()
Dim r As Range
Dim v()
Set r = Range("A1:A2")
v = r.Value
End Sub

work just fine, but:

Sub qwerty()
Dim r As Range
Dim v()
Set r = Range("A1:A1")
v = r.Value
End Sub

raise a type mismatch error?
--
Gary''s Student - gsnu200727




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy one array formula to an array range guedj54 Excel Programming 2 October 29th 06 07:38 PM
Tricky array formula issue - Using array formula on one cell, then autofilling down a range aspenbordr Excel Programming 0 July 27th 05 03:59 PM
Array <--- Range Charley Kyd[_2_] Excel Programming 7 January 14th 04 08:00 AM
Range as array J.E. McGimpsey Excel Programming 1 September 10th 03 11:06 PM
Range as array Chip Pearson Excel Programming 0 September 10th 03 10:40 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"