XL 2013 Redimensionner/Transposer le tableau variable 2D

hemerode

XLDnaute Junior
Bonjour à tous,
J'ai ce tableau variable de 2D
Dim arrExemple(), p
ReDim arrExemple(1 To 3, 1 To 5)

Je veux modifier la 1ere dimension.

arrExemple = Application.Transpose(arrExemple)

ReDim arrExemple(1 To 5, 1 To p)

arrExemple = Application.Transpose(arrExemple)

Cela fonctionne mais lorsque p=1

Debug.Print UBound(arrExemple)

J'obtiens 2 au lieu de 1.

Merci d'avance pour votre aide.
 
Solution
Bonjour,
C'est l'effet Kisscool de Application.Transpose.
Pour contourner cet effet, il est simple d'écrire sa propre fonction Transpose.
Voici la mienne ci-dessous. L'appel est simple, par exemple : arrExemple = Transpose(arrExemple)
VB:
' Auteur : Pierre - P56 - http://tatiak.canalblog.com/
Function Transpose(Ttk As Variant) As Variant
Dim T As Variant, i As Long, j As Long

    ReDim T(LBound(Ttk, 2) To UBound(Ttk, 2), LBound(Ttk, 1) To UBound(Ttk, 1))
    For i = LBound(Ttk, 2) To UBound(Ttk, 2)
        For j = LBound(Ttk, 1) To UBound(Ttk, 1)
            T(i, j) = Ttk(j, i)
        Next j
    Next i
    Transpose = T
End Function

p56

XLDnaute Occasionnel
Bonjour,
C'est l'effet Kisscool de Application.Transpose.
Pour contourner cet effet, il est simple d'écrire sa propre fonction Transpose.
Voici la mienne ci-dessous. L'appel est simple, par exemple : arrExemple = Transpose(arrExemple)
VB:
' Auteur : Pierre - P56 - http://tatiak.canalblog.com/
Function Transpose(Ttk As Variant) As Variant
Dim T As Variant, i As Long, j As Long

    ReDim T(LBound(Ttk, 2) To UBound(Ttk, 2), LBound(Ttk, 1) To UBound(Ttk, 1))
    For i = LBound(Ttk, 2) To UBound(Ttk, 2)
        For j = LBound(Ttk, 1) To UBound(Ttk, 1)
            T(i, j) = Ttk(j, i)
        Next j
    Next i
    Transpose = T
End Function
 

hemerode

XLDnaute Junior
Bonjour,
C'est l'effet Kisscool de Application.Transpose.
Pour contourner cet effet, il est simple d'écrire sa propre fonction Transpose.
Voici la mienne ci-dessous. L'appel est simple, par exemple : arrExemple = Transpose(arrExemple)
VB:
' Auteur : Pierre - P56 - http://tatiak.canalblog.com/
Function Transpose(Ttk As Variant) As Variant
Dim T As Variant, i As Long, j As Long

    ReDim T(LBound(Ttk, 2) To UBound(Ttk, 2), LBound(Ttk, 1) To UBound(Ttk, 1))
    For i = LBound(Ttk, 2) To UBound(Ttk, 2)
        For j = LBound(Ttk, 1) To UBound(Ttk, 1)
            T(i, j) = Ttk(j, i)
        Next j
    Next i
    Transpose = T
End Function
Merci Pierre pour votre aide.
 

Discussions similaires

Réponses
19
Affichages
2 K

Statistiques des forums

Discussions
312 147
Messages
2 085 767
Membres
102 968
dernier inscrit
Tmarti