Boucle - Création d'onglet

MERLIN

XLDnaute Junior
Bonsoir à tous !!

Je n'arrive pas à créer une macro laquelle pourrait créer autant d'onglet qu'il y a de valeur dans la colonne A sans les doublons bien évidemment. (voir fichier en PJ)
L'onglet devrait porter le nom = Code & "-" & Nom.

D'avance merci car je suis encore au stade d'apprenti dans le domaine des boucles.
ET je buche dessus depuis quelques temps...
MERLIN
 

Pièces jointes

  • boucle.xls
    17 KB · Affichages: 49
  • boucle.xls
    17 KB · Affichages: 52
  • boucle.xls
    17 KB · Affichages: 61

ROGER2327

XLDnaute Barbatruc
Re : Boucle - Création d'onglet

Bonjour MERLIN
Essayez cette procédure :
Code:
[COLOR="DarkSlateGray"][B]
CODE SUPPRIMÉ

Voir le message #5[/B][/COLOR]
À placer de le module de la feuille Feuil1" ou dans un module standard.​
ROGER2327
#3221
 
Dernière édition:

MERLIN

XLDnaute Junior
Re : Boucle - Création d'onglet

Bonjour MERLIN
Essayez cette procédure :
Code:
[COLOR="DarkSlateGray"][B]Sub toto()
Dim oDat, i&
   Application.ScreenUpdating = False
   On Error GoTo E
   With Sheets("Feuil1")
      oDat = Intersect(.Range(.Range("A2"), .Range("A2").SpecialCells(xlCellTypeLastCell)), .Columns("A:B")).Value
   End With
   On Error GoTo 0
   If IsEmpty(oDat) Then GoTo E
   For i = 1 To UBound(oDat, 1)
      If oDat(i, 1) & "-" & oDat(i, 2) <> "-" Then
         Application.Worksheets.Add After:=Me
         On Error GoTo S
         ActiveSheet.Name = Format(oDat(i, 1), "0000") & "-" & oDat(i, 2)
         On Error GoTo 0
      End If
   Next i
E: Application.ScreenUpdating = True
Exit Sub
'
S: Application.DisplayAlerts = False
   ActiveSheet.Delete
   Application.DisplayAlerts = True
   Resume Next
End Sub[/B][/COLOR]
À placer de le module de la feuille Feuil1" ou dans un module standard.​
ROGER2327
#3221

Bonjour ROGER2327,

Lorsque je lance la macro. J'ai le droit à ce gentil message...
"Erreur de compilation : utilisation incorrecte du mot clé Me"
 

ROGER2327

XLDnaute Barbatruc
Re : Boucle - Création d'onglet

Re...
Bonjour ROGER2327,

Lorsque je lance la macro. J'ai le droit à ce gentil message...
"Erreur de compilation : utilisation incorrecte du mot clé Me"
Normal ! J'ai commis une énorme bourde...
Code:
[COLOR="DarkSlateGray"][B]Sub toto()
Dim oDat, i&
   Application.ScreenUpdating = False
   On Error GoTo E
   With Sheets("Feuil1")
      oDat = Intersect(.Range(.Range("A2"), .Range("A2").SpecialCells(xlCellTypeLastCell)), .Columns("A:B")).Value
      On Error GoTo 0
      If IsEmpty(oDat) Then GoTo E
      For i = 1 To UBound(oDat, 1)
         If oDat(i, 1) & "-" & oDat(i, 2) <> "-" Then
            Application.Worksheets.Add After:=[COLOR="Red"]Sheets(.Name)[/COLOR]
            On Error GoTo S
            ActiveSheet.Name = Format(oDat(i, 1), "0000") & "-" & oDat(i, 2)
            On Error GoTo 0
         End If
      Next i
   [COLOR="Red"]End With[/COLOR]
E: Application.ScreenUpdating = True
Exit Sub
'
S: Application.DisplayAlerts = False
   ActiveSheet.Delete
   Application.DisplayAlerts = True
   Resume Next
End Sub[/B][/COLOR]
devrait être mieux.
Mille excuses !​
ROGER2327
#3223
 

Discussions similaires

Statistiques des forums

Discussions
312 497
Messages
2 088 992
Membres
104 000
dernier inscrit
dinelcia