XL 2010 [RESOLU]Récupérer valeurs tableau d'une autre Sub

herve62

XLDnaute Barbatruc
Supporter XLD
Bonsoir
D'une sub je fais appel à une autre ou je rempli un petit tableau Tab_j(x)
lors du retour dans la sub principale je veux relire ce tableau mais il est vide ??

les 2 sub sont dan un module , j'ai mis Public tab_J ()
VB:
Sub Find_replace()
Dim tab_J(3)
    ref = .Cells(5, 4)
    trouve_ref
   
    For y = 6 To 65
    If .Cells(x, y) = "X" Then
        For Z = 1 To 3
        If .Cells(3, y) = tab_J(Z) Then .Cells(x, y) = "ok"
        Next Z
     End If
    Next y
   
End Sub
----------------
Sub trouve_ref()
Dim tab_J(3)
For j = 1 To 3
tab_J(j) = .Cells(5, j + 30)
Next j
end sub
 

job75

XLDnaute Barbatruc
Bonjour herve62,

Désolé mais votre code m'est assez incompréhensible.

Alors en supposant que vous voulez copier le tableau en Feuil2 pour le coller sur le tableau en Feuil1 :
VB:
Sub Copier_coller()
Dim d As Object, tablo, ncol%, i&, j%, x$
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare 'la casse est ignorée
'---mémorisation des valeurs du tableau source ---
tablo = Feuil2.[A2].CurrentRegion
If Not IsArray(tablo) Then MsgBox "Le tableau source n'existe pas...": Exit Sub
ncol = UBound(tablo, 2)
For i = 2 To UBound(tablo)
    For j = 2 To ncol
        d(tablo(i, 1) & Chr(1) & tablo(1, j)) = tablo(i, j)
Next j, i
'---tableau de destination---
With Feuil1.[A4].CurrentRegion
    tablo = .Value
    If Not IsArray(tablo) Then MsgBox "Le tableau de destination n'existe pas...": Exit Sub
    ncol = UBound(tablo, 2)
    For i = 2 To UBound(tablo)
        For j = 2 To ncol
            x = tablo(i, 1) & Chr(1) & tablo(1, j)
            If d.exists(x) Then tablo(i, j) = d(x)
    Next j, i
    .Value = tablo 'restitution
End With
End Sub
A+
 

Pièces jointes

  • Tableau_2sub(1).xlsm
    20 KB · Affichages: 1

Discussions similaires

Réponses
17
Affichages
760

Statistiques des forums

Discussions
311 716
Messages
2 081 828
Membres
101 823
dernier inscrit
mohamed3s