XL 2013 Redimensionner/Transposer le tableau variable 2D

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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
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
 
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.
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
5
Affichages
533
  • Question Question
Microsoft 365 VBA Transpose
Réponses
11
Affichages
753
Réponses
33
Affichages
3 K
Retour