Array +fonction+vba

T

Tom Ogilvy

Sub combinearrays()
Dim tab1, tab2, tab3
Dim lb1 As Long, lb2 As Long
Dim ub1 As Long, ub2 As Long
Dim n As Long, n1 As Long
Dim i As Long, s As String
tab1 = Array(1, 2, 3, 4)
tab2 = Array(1, 2, 5, 6, 7, 8, 9, 10, 11, 12)
lb1 = LBound(tab1)
ub1 = UBound(tab1)
lb2 = LBound(tab2)
ub2 = UBound(tab2)
n = ub1 - lb1 + 1 + ub2 - lb2 + 1

ReDim tab3(1 To n)
n1 = 0
For i = lb1 To ub1
n1 = n1 + 1
tab3(n1) = tab1(i)
s = s & tab3(n1) & ","
Next
For i = lb2 To ub2
n1 = n1 + 1
tab3(n1) = tab2(i)
s = s & tab3(n1) & ","
Next
Debug.Print UBound(tab3) - LBound(tab3) + 1
Debug.Print Left(s, Len(s) - 1)
End Sub
 
P

PST

Hello

Array +fonction+vba

That is to say 2 arrays Tab1(4) and Tab2(10)

I would like Tab1+Tab2 = tab3(14) and knowledge if it is posible
to apply a function to an array

Ex: Aplication.Worshetfunction.Average(Tab3)
Average is just an example not the right function


Different need to know the number of element in Tab3 without loops

ex:

Array1 (1,2,3,4)

Array2 (1,2,5,6,7,8,9,10,11,12)

Array1+Array2=Array3


Array3(1,2,1,2,3,4,5,6,7,8,9,10,11,12)

12 different number

Thank you
 

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

Top