Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Is there a simple way to combing 1D arrays?

Hi. Here's something a little different.
Note that the array v1 and v2 are slightly different in their dimensions.
I had some test data in A1:C3, and I included a number in the array. This
probably could be written a little better...

Sub Example()
Dim v1, v2, v3, v4
Dim MyArray As Variant
v1 = [A1:A3]
v2 = [Transpose(A1:A3)]
v3 = [B1:B3]
v4 = [C1:C3]
MyArray = Flatten(v1, v2, v3, 3.14, v4)
End Sub

Function Flatten(ParamArray m() As Variant)
Dim J As Long
Dim R As Long
Dim C As Long
Dim n As Long
Dim d As Variant

Set d = CreateObject("Scripting.Dictionary")
n = 1

For J = LBound(m) To UBound(m)
Select Case ArrayDepth(m(J))
Case 0
d.Add n, m(J)
n = n + 1
Case 1
For R = LBound(m(J)) To UBound(m(J))
d.Add n, m(J)(R)
n = n + 1
Next R
Case 2
For R = LBound(m(J), 1) To UBound(m(J), 1)
For C = LBound(m(J), 2) To UBound(m(J), 2)
d.Add n, m(J)(R, C)
n = n + 1
Next C
Next R
Case Else
'Not sure...
End Select
Next J
Flatten = d.items
End Function

Function ArrayDepth(v) As Long
Dim n As Long
Dim Dummy As Long

If Not IsArray(v) Then
ArrayDepth = 0
Exit Function
End If

On Error Resume Next
Do While Err.Number = 0
n = n + 1
Dummy = UBound(v, n)
Loop
ArrayDepth = n - 1
End Function


--
HTH :)
Dana DeLouis
Windows XP & Office 2007


"Steve" <No Spam wrote in message ...
Tom

Thank you. I made a few modifications to get around my bad question but, I
havve it working exactly as I need.

Steve


"Tom Ogilvy" wrote in message
...
Using 3 ranges as an example:

Dim arr(), rng as range, cell as Range
Dim i as Long
set rng = Range("A1:A7,B1:B7,C1:C7")
redim arr(1 to rng.count)
i = 0
for each cell in rng
i = i + 1
arr(i) = cell.value
Next

.

Another way would be to copy the values to a single column on the
worksheet, pick them up from there and use transpose to make is 1D,
however, this would probably be slower.

--
Regards,
Tom Ogilvy

"Steve" <No Spam wrote in message ...
I need to be able to combine multipe arrays into another 1D array in
order

Array1 = Range ("A1:A7")
Array2 = Range ("B1:B7")
Array3 = Range("C1:C7")
etc, etc, etc (it could get very large)

The result should be a 1D array. Assuming only the three arrays above,
LBOUND value should be A1.value. UBOUND value should be C7.value.










Reply
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
fast and simple way to match up arrays RB Smissaert Excel Programming 2 March 25th 05 04:41 AM
combing cells Kelly E. Excel Programming 3 January 27th 05 02:33 PM
Combing Workbooks GazMo[_6_] Excel Programming 1 October 20th 04 01:53 AM
Combing Workbooks GazMo[_5_] Excel Programming 1 October 19th 04 03:45 AM
Simple arrays with If statements Andy Excel Programming 4 September 23rd 03 06:15 PM


All times are GMT +1. The time now is 10:03 PM.

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"