Option Explicit Private Sub CommandButton1_Click() NouvelleFeuille End Sub Private Sub CommandButton2_Click() Triercolonne_croissant End Sub Private Sub CommandButton3_Click() Triercolonne_decroissant End Sub Private Sub CommandButton4_Click() TrierFeuilles_croissant End Sub Private Sub CommandButton5_Click() TrierFeuilles_decroissant End Sub Sub NouvelleFeuille() Dim Sh As Worksheet Dim Reponse As String Dim MonNom As String Dim BonNom As Boolean Dim LeString Dim supp Dim ligne As Integer Dim a As Integer LeString = ":\/?*[]" Do BonNom = True Reponse = InputBox("Quel nom désirez-vous donner à la" _ + vbCrLf + "nouvelle feuille de votre classeur?", _ "Baptisez votre feuille ", MonNom) If Reponse <> "" Then 'Vérifier que le nom n'existe pas déjà... For a = 1 To ActiveWorkbook.Worksheets.Count If UCase(Reponse) = UCase(Worksheets(a).Name) Then supp = MsgBox( _ "Vous possédez une feuille portant déjà ce nom," _ + vbCrLf + vbCrLf + _ "Désirez-vous la remplacer?.", vbYesNo + vbOKOnly, _ "Nom existant déjà") If supp = vbYes Then Application.DisplayAlerts = False Worksheets(Reponse).Delete Application.DisplayAlerts = True Exit For Else BonNom = False MonNom = Reponse Exit For End If End If Next 'Vérifier que le nombre de caractères du nom ne dépassent 31... If Len(Reponse) > 31 Then MsgBox "Le nombre de caractères (" & _ Len(Reponse) & ") de votre nom dépasse" _ + vbCrLf + " celui permis (31) par excel.", _ vbCritical + vbInformation, "Nom trop long" BonNom = False MonNom = Reponse End If 'Vérifier l'emploi de caractères interdits...dans le nom For a = 1 To Len(LeString) If InStr(1, Reponse, Mid(LeString, a, 1), vbTextCompare) > 0 Then MsgBox "Les caractères suivants: " & _ LeString & " sont interdits" _ + vbCrLf + "dans le nom d'une feuille.", _ vbCritical + vbOKOnly, "Caractère interdit" BonNom = False MonNom = Reponse Exit For End If Next Else Exit Sub End If Loop Until BonNom = True Set Sh = Worksheets.Add(After:=Worksheets(Worksheets.Count)) Sh.Name = Reponse 'sélection interface Worksheets("Feuil1").Select 'dernière ligne feuille active, colonne A ligne = Cells(Cells.Rows.Count, "A").End(xlUp).Row 'lien hypertexte vers nouvelle feuille Range("A" & ligne).Select 'sélection dernière ligne If Range("A1").Value = "" Then 'pour la 1ère utilisation ActiveCell.FormulaR1C1 = Reponse 'Nom de la feuille Else ActiveCell.Offset(1, 0).Select 'sélection cellule en dessous ActiveCell.FormulaR1C1 = Reponse 'Nom de la feuille End If ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _ Reponse & "!A1", TextToDisplay:=Reponse 'sélection nouvelle feuille Worksheets(Reponse).Select 'lien hypertexte vers l'interface Range("A1").Select ActiveCell.FormulaR1C1 = Reponse 'Nom de la feuille ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _ "Feuil1!A1", TextToDisplay:="Retour " & "Feuil1" End Sub Sub Triercolonne_croissant() 'sélection interface Worksheets("Feuil1").Select Columns("A:A").Select Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub Sub Triercolonne_decroissant() 'sélection interface Worksheets("Feuil1").Select Columns("A:A").Select Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub Sub TrierFeuilles_croissant() 'attention : feuil11 est trié entre feuil1 et feuil2 Dim I As Integer, J As Integer, K As Integer Application.ScreenUpdating = False For I = 1 To Sheets.Count J = I For K = I + 1 To Sheets.Count If Sheets(K).Name < Sheets(J).Name Then J = K Next K If J <> I Then Sheets(J).Move Sheets(I) Next I End Sub Sub TrierFeuilles_decroissant() 'attention : feuil11 est trié entre feuil1 et feuil2 Dim I As Integer, J As Integer, K As Integer Application.ScreenUpdating = False For I = 1 To Sheets.Count J = I For K = I + 1 To Sheets.Count If Sheets(K).Name > Sheets(J).Name Then J = K Next K If J <> I Then Sheets(J).Move Sheets(I) Next I End Sub
Sub Add_competitor() Dim Sh As Worksheet Dim Reponse As String Dim MonNom As String Dim BonNom As Boolean Dim LeString LeString = ":\/?*[]" Do BonNom = True Reponse = InputBox("Please write here the name of the competitor", _ "Name of the sheet", MonNom) If Reponse <> "" Then 'Vérifier que le nom n'existe pas déjà... For a = 1 To ActiveWorkbook.Worksheets.Count If UCase(Reponse) = UCase(Worksheets(a).Name) Then supp = MsgBox( _ "Competitor already exists (or this sheet already exists)" _ + vbCrLf + vbCrLf + _ "Would you like to replace it?.", vbYesNo + vbOKOnly, _ "Name already existing") If supp = vbYes Then Application.DisplayAlerts = False Worksheets(Reponse).Delete Application.DisplayAlerts = True Exit For Else BonNom = False MonNom = Reponse Exit For End If End If Next 'Vérifier que le nombre de caractères du nom ne dépassent 31... If Len(Reponse) > 31 Then MsgBox "Le nombre de caractères (" & _ Len(Reponse) & ") de votre nom dépasse" _ + vbCrLf + " celui permis (31) par excel.", _ vbCritical + vbInformation, "Name too long" BonNom = False MonNom = Reponse End If 'Vérifier l'emploi de caractères interdits...dans le nom For a = 1 To Len(LeString) If InStr(1, Reponse, Mid(LeString, a, 1), vbTextCompare) > 0 Then MsgBox "Les caractères suivants: " & _ LeString & " sont interdits" _ + vbCrLf + "dans le nom d'une feuille.", _ vbCritical + vbOKOnly, "Forbidden caracter" BonNom = False MonNom = Reponse Exit For End If Next Else Exit Sub End If Loop Until BonNom = True Set Sh = Worksheets.Add(after:=Worksheets(Worksheets.Count)) Sh.Name = Reponse ' Tier les feuilles de A a Z Dim Boucle As Integer, Compteur As Integer For Boucle = 1 To Sheets.Count If Sheets(Boucle).Visible = True Then For Compteur = 1 To (Boucle - 1) If Sheets(Compteur).Visible = True Then If (UCase(Sheets(Boucle).Name) < UCase(Sheets(Compteur).Name)) Then Sheets(Boucle).Move before:=Sheets(Compteur) Exit For End If End If Next Compteur End If Next Boucle ' ' Get info from 4.Example, copy paste it all in the new sheet ' Sheets("4.Example").Select Cells.Select selection.Copy Range("A1").Select Sheets(Reponse).Select ActiveSheet.Paste Range("A1").Select Rows("1:1").RowHeight = 91.5 Sheets("4.Example").Select Application.CutCopyMode = False Sheets(Reponse).Select Range("A1").Select ActiveWindow.Zoom = 90 ' Name Cell B3 (company name) ' Range("B3").FormulaR1C1 = Reponse With Range("B3").Characters(Start:=1, Length:=7).Font .Name = "Calibri" .FontStyle = "Normal" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ThemeColor = xlThemeColorLight1 .TintAndShade = 0 .ThemeFont = xlThemeFontMinor End With ' Nommer la cellule dans overview Sheets("2.Overview").Select Range("A60").Select 'Mettre le nom de la nouvelle compagnie en bas d'une liste avec assez d'espace entre celles existantes et A60 ActiveCell.FormulaR1C1 = Reponse 'Recherche V et etendre la selection ' Range("B60").Select ' ActiveCell.FormulaR1C1 = "=VLOOKUP(R2C,Reponse!C1:C2,2,FALSE)" ' Range("B60").Select ' selection.AutoFill Destination:=Range("B60:CX60"), Type:=xlFillDefault 'Range("B60:CX60").Select 'Sub Tri_Overview() ' ' Tri_Overview Macro ' ' ' Sheets("2.Overview").Select 'Range("A3:CX60").Select 'ActiveWorkbook.Worksheets("2.Overview").Sort.SortFields.Clear 'ActiveWorkbook.Worksheets("2.Overview").Sort.SortFields.Add Key:=Range("A3") _ ' , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal 'With ActiveWorkbook.Worksheets("2.Overview").Sort ' .SetRange Range("A4:CX60") ' .Header = xlNo ' .MatchCase = False ' .Orientation = xlTopToBottom '.SortMethod = xlPinYin '.Apply 'End With Sheets(Reponse).Select Range("A1").Select End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionActiveCell.FormulaR1C1 = "=VLOOKUP(R2C,Reponse!C1:C2,2,FALSE)"
ActiveCell.FormulaR1C1 = "=RechercheV(R2C,Reponse,C1:C2,2,FALSE)"
Range("B60").Select ActiveCell.FormulaR1C1 = "=VLOOKUP(R2C," & Reponse & "!C1:C2,2,FALSE)"