'VERSION 1
Function TransposeXV1(T, Optional lBase1& = -1, Optional lBase2& = -1)
'patricktoulon V 1.2 -- 08/07/2021
'Ajout du change base V 1.2.1 -- 08/12/2024 méthode Addition nombre relatif
Dim y&, i&, C&, T2(), LB1%, LB2%
If TypeOf T Is Range Then T = T.Value
If Not IsArray(T) Then TransposeXV1 = T
If lBase1 > 1 Then lBase1 = 1 ' au cas ou il vous prendrez l'envie de faire nimporte quoi
If lBase2 > 1 Then lBase2 = 1 ' au cas ou il vous prendrez l'envie de faire nimporte quoi
On Error Resume Next
y = UBound(T, 2)
On Error GoTo 0
'b1 et b2 deviendront les reducteurs ou augmenteur de dimension (++/+-)
If lBase1 > -1 Then LB1 = Sgn(lBase1 - LBound(T))
If y = 0 Then
ReDim T2(LBound(T) + LB1 To UBound(T) + LB1, LBound(T) + LB1 To LBound(T) + LB1)
Else
If lBase2 > -1 Then LB2 = Sgn(lBase2 - LBound(T, 2))
ReDim T2(LBound(T, 2) + LB2 To UBound(T, 2) + LB2, LBound(T) + LB1 To UBound(T) + LB1)
End If
For i = LBound(T) To UBound(T)
If y = 0 Then
T2(i + LB1, 1) = T(i)
Else
For C = LBound(T, 2) To UBound(T, 2)
T2(C + LB2, i + LB2) = T(i, C)
Next
End If
Next
TransposeXV1 = T2
End Function
'VERSION 2
Function TransposeXV2(T, Optional lBase1& = -1, Optional lBase2& = -1)
'Ajout du change base V 1.2.1 -- 08/12/2024 méthode Addition nombre relatif en select case
'patricktoulon V 1.3 -- 10/12/2024
'version 1.3 avec un select case
Dim y&, i&, C&, T2(), LB1%, LB2%
If TypeOf T Is Range Then T = T.Value
If Not IsArray(T) Then TransposeXV2 = T
If lBase1 > 1 Then lBase1 = 1 ' au cas ou il vous prendrez l'envie de faire nimporte quoi
On Error Resume Next
y = UBound(T, 2)
'b1 et b2 deviendront les reducteurs ou augmenteur de dimension (++/+-)
Select Case True
Case Err.Number <> 0
If lBase1 > -1 Then LB1 = Sgn(lBase1 - LBound(T))
ReDim T2(LBound(T) + LB1 To UBound(T) + LB1, LBound(T) + LB1 To LBound(T) + LB1)
For i = LBound(T) To UBound(T): T2(i + LB1, 1) = T(i): Next
On Error GoTo 0
Case Else
If lBase2 > -1 Then LB2 = Sgn(lBase2 - LBound(T, 2))
ReDim T2(LBound(T, 2) + LB2 To UBound(T, 2) + LB2, LBound(T) + LB1 To UBound(T) + LB1)
For i = LBound(T) To UBound(T)
For C = LBound(T, 2) To UBound(T, 2): T2(C + LB2, i + LB2) = T(i, C): Next
Next
End Select
TransposeXV2 = T2
End Function