"Etre sur la même feuille" en VBA
Résolu/Fermé
A voir également:
- "Etre sur la même feuille" en VBA
- Feuille de pointage excel - Télécharger - Tableur
- Feuille a5 - Guide
- Comment supprimer une feuille sur word - Guide
- Verrouiller cellule excel sans verrouiller la feuille - Guide
- Erreur 1004 vba ✓ - Forum VB / VBA
6 réponses
J'ai tenté ça mais ça marche pas:
If [B:B].Find(Wbk2.Worksheets("Structure").Cells(I, 8).Value, LookIn:=xlValues, lookat:=xlWhole) = True & [B:B].Find(Wbk2.Worksheets("Structure").Cells(I + 1, 8).Value, LookIn:=xlValues, lookat:=xlWhole) = True Then
J'ai vraiment besoin d'aide, merci à tous ceux qui m'aidront
If [B:B].Find(Wbk2.Worksheets("Structure").Cells(I, 8).Value, LookIn:=xlValues, lookat:=xlWhole) = True & [B:B].Find(Wbk2.Worksheets("Structure").Cells(I + 1, 8).Value, LookIn:=xlValues, lookat:=xlWhole) = True Then
J'ai vraiment besoin d'aide, merci à tous ceux qui m'aidront
gbinforme
Messages postés
14946
Date d'inscription
lundi 18 octobre 2004
Statut
Contributeur
Dernière intervention
24 juin 2020
4 684
20 juin 2012 à 22:42
20 juin 2012 à 22:42
bonjour
Si tu pouvais nous mettre un exemple sans éléments personnels mais avec la structure des données sur https://www.cjoint.com/ puis nous mettre le lien généré ici ce serait plus facile.
Si tu pouvais nous mettre un exemple sans éléments personnels mais avec la structure des données sur https://www.cjoint.com/ puis nous mettre le lien généré ici ce serait plus facile.
Voila, j'ai 2 classeurs je voudrais vérifier si 2 éléments consécutifs de la colonne "éléments" dans le classeur2 se trouvent sur une même feuille dans le classeur1. Si oui, je veux que le nom de l'onglet soit copier en face des 2 éléments comparées dans la colonne "nom" du classeur2.
Si nom, passer au 2 prochains termes.
Et ainsi de suite...
Voici les 2 fichiers et ma tentative de code:
http://cjoint.com/?3FvaXtcL7G3
http://cjoint.com/?3FvaXYCyRLg
Dim Wbk1 As Workbook, Wbk2 As Workbook
Dim ws As Worksheet
Dim ws_count As Integer
Set Wbk1 = ThisWorkbook
Set Wbk2 = Workbooks("Classeur2.xls")
ws_count = ActiveWorkbook.Worksheets.Count
For I = 2 To 7
For J = 1 To ws_count
Wbk1.Worksheets(J).Activate
If [B:B].Find(Wbk2.Worksheets("Feuil1").Cells(I, 5).Value, LookIn:=xlValues, lookat:=xlWhole) = True And [B:B].Find(Wbk2.Worksheets("Feuil1").Cells(I + 1, 5).Value, LookIn:=xlValues, lookat:=xlWhole) = True Then
Wbk2.Worksheets("Feuil1").Cells(I, 3) = Wbk1.Worksheets(I).Name
Wbk2.Worksheets("Feuil1").Cells(I + 1, 3) = Wbk1.Worksheets(I).Name
Else
End If
Next J
Next I
Si nom, passer au 2 prochains termes.
Et ainsi de suite...
Voici les 2 fichiers et ma tentative de code:
http://cjoint.com/?3FvaXtcL7G3
http://cjoint.com/?3FvaXYCyRLg
Dim Wbk1 As Workbook, Wbk2 As Workbook
Dim ws As Worksheet
Dim ws_count As Integer
Set Wbk1 = ThisWorkbook
Set Wbk2 = Workbooks("Classeur2.xls")
ws_count = ActiveWorkbook.Worksheets.Count
For I = 2 To 7
For J = 1 To ws_count
Wbk1.Worksheets(J).Activate
If [B:B].Find(Wbk2.Worksheets("Feuil1").Cells(I, 5).Value, LookIn:=xlValues, lookat:=xlWhole) = True And [B:B].Find(Wbk2.Worksheets("Feuil1").Cells(I + 1, 5).Value, LookIn:=xlValues, lookat:=xlWhole) = True Then
Wbk2.Worksheets("Feuil1").Cells(I, 3) = Wbk1.Worksheets(I).Name
Wbk2.Worksheets("Feuil1").Cells(I + 1, 3) = Wbk1.Worksheets(I).Name
Else
End If
Next J
Next I
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
eriiic
Messages postés
24570
Date d'inscription
mardi 11 septembre 2007
Statut
Contributeur
Dernière intervention
23 avril 2024
7 213
21 juin 2012 à 01:41
21 juin 2012 à 01:41
Bonsoir tout le monde,
pas :
If [B:B].Find(...) = True
mais :
If not [B:B].Find(...) is nothing
Je n'ai pas testé ton code avec cette modif, j'ai vu l'erreur après avoir créé le mien.
eric
pas :
If [B:B].Find(...) = True
mais :
If not [B:B].Find(...) is nothing
Je n'ai pas testé ton code avec cette modif, j'ai vu l'erreur après avoir créé le mien.
Dim wb2 As Workbook, sh1 As Worksheet, sh2 As Worksheet Dim item1 As String, item2 As String, c1 As Range, c2 As Range Dim lig As Long Set sh1 = Workbooks("classeur2.xlsx").Worksheets("Feuil1") Set wb2 = Workbooks("classeur1.xlsx") For lig = 2 To sh1.[E65536].End(xlUp).Row Step 2 item1 = sh1.Cells(lig, 5) item2 = sh1.Cells(lig + 1, 5) For Each sh2 In wb2.Worksheets Set c1 = sh2.Cells.Find(item1, LookIn:=xlValues, LookAt:=xlWhole) Set c2 = sh2.Cells.Find(item2, LookIn:=xlValues, LookAt:=xlWhole) If Not c1 Is Nothing And Not c2 Is Nothing Then sh1.Cells(lig, 6) = sh2.Name sh1.Cells(lig + 1, 6) = sh2.Name Exit For End If Next sh2 Next lig
eric