Importation d'informations
Résolu/Fermé
A voir également:
- Importation d'informations
- Entrer les informations d'identification reseau - Guide
- Merci d'avoir fourni vos informations ✓ - Forum Instagram
- Echec d'importation instagram ✓ - Forum Samsung
- Nous n'avons pas pu vous connecter avec ces informations d'identification car votre domaine ✓ - Forum Windows
- Une erreur critique est survenue sur ce site. veuillez consulter la boite de réception de l’e-mail d’administration de votre site pour plus d’informations. ✓ - Forum Wordpress
1 réponse
f894009
Messages postés
16904
Date d'inscription
dimanche 25 novembre 2007
Statut
Membre
Dernière intervention
18 mars 2023
1 678
1 juil. 2016 à 16:31
1 juil. 2016 à 16:31
Bonjour,
quelques modifs de votre code et des lignes en plus
quelques modifs de votre code et des lignes en plus
Sub Macro1()
Dim Dico_Data As Object, PlageA, PlageB, derlig1, x, Fin
'Application.ScreenUpdating = False
'fichier A
Set Dico_Data = CreateObject("Scripting.Dictionary")
With Worksheets("feuil1")
derlig1 = .Range("A" & Rows.Count).End(xlUp).Row 'derniere cellule non vide colonne A
PlageA = .Range("A2:A" & derlig1) 'mise en memoire
End With
'boucle sur plage
Fin = UBound(PlageA, 1) 'longueur table
For x = 1 To Fin
Dico_Data(PlageA(x, 1)) = x + 1 'mise en memoire ref et ligne ref dans dictionnaire---->x+1 pour ligne 2
Next x
'ouverture et recup fichier B
Application.FileDialog(msoFileDialogOpen).Filters.Add "Excel files (*.xlsx)", "*.xlsx", 1 'prend en compte la boîte de dialogue permettant l'ouverture d'un fichier
If Not (Application.FileDialog(msoFileDialogOpen).Show) Then
MsgBox "Pas de fichier selectionne !!!!!.", vbExclamation, "PAS BIEN !!!!!!!!"
Application.ScreenUpdating = True
Exit Sub
End If
With Application.FileDialog(msoFileDialogOpen)
Workbooks.Open (.SelectedItems(1)) 'ouvre le premier fichier sélectionné et ferme la boîte de dialogue (génère une erreur si bouton [Annuler])
nom_Fichier = Right(.SelectedItems(1), Len(.SelectedItems(1)) - InStrRev(.SelectedItems(1), "\")) 'nom de fichier avec extention
End With
With Workbooks(nom_Fichier).Worksheets("feuil1")
derlig1 = .Range("A" & Rows.Count).End(xlUp).Row 'derniere cellule non vide colonne A
PlageB = .Range("A2:O" & derlig1) 'mise en memoire plage de cellules fichier B
End With
Fin = UBound(PlageB) 'nombre de "ligne"
Workbooks(nom_Fichier).Close False
'retour fichier A
With Worksheets("feuil1")
For x = 1 To Fin
If Dico_Data.exists(PlageB(x, 1)) Then 'ref existe en A et B
Lg = Dico_Data(PlageB(x, 1)) 'ligne ref fichier A
.Range("K" & Lg) = PlageB(x, 11) 'ecriture des infos
.Range("L" & Lg) = PlageB(x, 12)
.Range("M" & Lg) = PlageB(x, 13)
.Range("N" & Lg) = PlageB(x, 14)
.Range("O" & Lg) = PlageB(x, 15)
End If
Next x
End With
Application.ScreenUpdating = True
End Sub
4 juil. 2016 à 09:55