Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Fonction VBA qui renvoie un tableau

2 réponses
Avatar
Patrick
Bonjour,

Est-il possible qu'une fonction personnalisée créée en VBA renvoie un
tableau ?
Si oui, comment faire ? Si non, y a-t-il une alternative ?

Merci pour votre aide.

--
Patrick

2 réponses

Avatar
FxM
Bonjour,

Est-il possible qu'une fonction personnalisée créée en VBA renvoie un
tableau ?
Si oui, comment faire ? Si non, y a-t-il une alternative ?

Merci pour votre aide.




Bonsoir Patrick,

alt-f11 | insertion | module
Public Function table1()
Dim tablo
a = 1: b = 2: ReDim tablo(1, 2)
For c = 0 To a
For d = 0 To b
tablo(c, d) = c & " / " & d
Next d
Next c
' table1 = tablo 'choix1
table1 = Application.Transpose(tablo) 'choix2
End Function

dans ta feuille de calculs :
si tu actives choix2 -> sélectionne A1:B3, tapes =table1() puis
validation matricielle

si tu actives choix1 -> sélectionne A1:C2, tapes =table1() puis
validation matricielle

Donc oui, il est possible de ... :o)

@+
FxM

Avatar
JB
Bonjour,

http://cjoint.com/?hChkCy3mtc

Fonction matricielle renvoyant un tableau:

2 syntaxes:
SansDoublons=temp ' 2
dimensions
SansDoublons=Application.Transpose(temp) ' 1 dimension

Function SansDoublons(champ As Range)
Dim temp()
ReDim temp(1 To champ.Count, 1 To 1) ' 2 dimensions
j = 1
For i = 1 To champ.Count
If IsError(Application.Match(champ(i), temp, 0)) _
And champ(i) <> "" And champ(i) <> 0 Then
temp(j, 1) = champ(i): j = j + 1
End If
Next i
SansDoublons = temp
End Function

Function SansDoublonsTrié(champ As Range)
Dim temp()
ReDim temp(1 To champ.Count) ' 1 dimension
j = 1
For i = 1 To champ.Count
If IsError(Application.Match(champ(i), temp, 0)) _
And champ(i) <> "" And champ(i) <> 0 Then
temp(j) = champ(i): j = j + 1
End If
Next i
Call tri(temp, 1, j - 1)
SansDoublonsTrié = Application.Transpose(temp)
End Function

Cordialement JB


Bonjour,

Est-il possible qu'une fonction personnalisée créée en VBA renvoie un
tableau ?
Si oui, comment faire ? Si non, y a-t-il une alternative ?

Merci pour votre aide.

--
Patrick