Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'Marquage de la sélection pour Exportations Multiples 'Validation (texte bouton TestAction différent de IMPORTER, aucune sélection en cours : sinon Exit) If Sheets("Archives").TestAction.Caption = "IMPORTER" _ Or Sheets("Data").Range("AS15").Value = 1 _ Then Exit Sub 'Sélection de la ligne d'Archive à Exporter (première cellule non vide, et au delà de la ligne 3: sinon Msg et Exit) If ActiveCell.Value = "" Or ActiveCell.Row <= 3 Then MsgBox "Veuillez Sélectionnez un Test valide", vbExclamation, "Validation" Exit Sub End If 'On y va! Sheets("Archives").Unprotect 'Pour EXPORTER une ou plusieurs Archives If Sheets("Archives").TestAction.Caption = "EXPORTER" Then For Each cell In Selection If Sheets("Archives").Range("A" & cell.Row).Font.ColorIndex <> 3 Then Sheets("Archives").Range("A" & cell.Row).Font.Bold = True Sheets("Archives").Range("A" & cell.Row).Font.ColorIndex = 3 'Reprise de l'info Row d'une sélection Sheets("Archives").Range("IT" & cell.Row).Value = cell.Row Else Sheets("Archives").Range("A" & cell.Row).Font.Bold = False Sheets("Archives").Range("A" & cell.Row).Font.ColorIndex = 0 Sheets("Archives").Range("IT" & cell.Row).Value = "" End If Next 'Pour EXTRAIRE une (et toujours une seule!) Archive Else Sheets("Archives").Range("A4:A" & Sheets("Archives").Range("A65536").End(xlUp).Row).Font.Bold = False Sheets("Archives").Range("A4:A" & Sheets("Archives").Range("A65536").End(xlUp).Row).Font.ColorIndex = 0 Sheets("Archives").Range("A" & ActiveCell.Row).Font.Bold = True Sheets("Archives").Range("A" & ActiveCell.Row).Font.ColorIndex = 3 End If Sheets("Archives").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _ , AllowSorting:=True End Sub Private Sub TestAction_Click() 'Bouton de traitement 'Supprimer If TestAction.Caption = "SUPPRIMER TEST" Then 'Suppression d'une et une seule Archive SupArchive 'Extraire un Test (données + mesures) ElseIf TestAction.Caption = "EXTRAIRE TEST" Then 'Extraction d'une et une seule Archive (Toutes les données) ExtraireTest 'Extraire un Site (données seulement) ElseIf TestAction.Caption = "EXTRAIRE SITE" Then 'Extraction d'une et une seule Archive (uniquement les données d'identification du Site) ExtraireSite ' Else 'Importation ou Exportation d'Archives VersArchives End If End Su
Sub VersArchives() Application.ScreenUpdating = False Fichier = ThisWorkbook.Name Application.DisplayFormulaBar = False 'IMPORTER 'If Sheets("Archives").TestAction.Caption "IMPORTER" Then LoadFichier 'EXPORTER 'ElseIf Sheets("Archives").TestAction.Caption "EXPORTER" Then Last = Sheets("Archives").Range("IT65536").End(xlUp).Row If Last = 2 Then Exit Sub Sheets("Data").Range("AS15").Value = 1 Sheets("Archives").Range("IT4:IT" & Last).Sort Key1:=Range("IT4"), Order1:=xlAscending 'Sélection de la ligne d'Archive à Exporter (première cellule non vide, et au delà de la ligne 3) If ActiveCell.Value = "" Or ActiveCell.Row <= 3 _ Then MsgBox "Veuillez Sélectionnez un Test valide", vbExclamation, "Validation": Exit Sub 'Extraction Nom Archive depuis feuille "Archives" Last = Sheets("Archives").Range("IT65536").End(xlUp).Row For K = 4 To Last rw = Range("IT" & K).Value NomArch = _ Sheets("Archives").Range("B" & rw).Value & "$" & _ Sheets("Archives").Range("C" & rw).Value & "$" & _ Sheets("Archives").Range("D" & rw).Value & "$" & _ Sheets("Archives").Range("E" & rw).Value & "$" & _ Sheets("Archives").Range("IV" & rw).Value 'Le fichier existe déjà ? FileExist = Dir("C:\InfiltroPass\Archives" & NomArch & ".xls") If FileExist <> "" Then 'Message d'alerte Msg = "Le fichier " & NomArch & " existe déjà" & vbNewLine & _ "Voulez-vous le remplacer ?" Style = vbYesNo + vbCritical + vbDefaultButton2 Title = "Gestion des Archives" Response = MsgBox(Msg, Style, Title) If Response = vbYes Then Kill ("C:\InfiltroPass\Archives" & NomArch & ".xls") Else 'Exit Sub GoTo Line1 End If End If 'Création du Fichier Excel "NomArch" dans C:\InfiltroPass\Archives Workbooks.Add Application.DisplayAlerts = False For i = Sheets.Count To 2 Step -1 Sheets(i).Delete Next i Application.DisplayAlerts = True Sheets(1).Name = "Archives" For i = 2 To 8 Sheets.Add.Move After:=Sheets(i - 1) Sheets(i).Name = "Arch(" & i & ")" Next i Sheets("Archives").Select ChDir "C:\InfiltroPass\Archives" ActiveWorkbook.SaveAs Filename:="C:\InfiltroPass\Archives" & NomArch & ".xls" Windows(Fichier).Activate ActiveSheet.Unprotect ActiveWindow.DisplayHeadings = True 'Recopies les valeurs de mesure du premier Ventilateur Rows(rw).Select Selection.Copy Windows(NomArch & ".xls").Activate Rows("1:1").Select ActiveSheet.Paste Application.CutCopyMode = False Cells.Columns.AutoFit Cells.EntireRow.Hidden = False Range("A1").ClearContents Range("A1").Select 'Recopies identiques pour les valeurs de mesure des ventilateurs supplémentaires For w = 2 To 8 Windows(Fichier).Activate If Sheets("Arch (" & w & ")").Range("B" & rw) = 0 _ Or Sheets("Arch (" & w & ")").Range("B" & rw) = "" _ Then Exit For Sheets("Arch (" & w & ")").Unprotect Sheets("Arch (" & w & ")").Rows("" & rw & ":" & rw & "").Copy Windows(NomArch & ".xls").Activate Sheets(w).Select ActiveSheet.Paste Application.CutCopyMode = False Cells.Columns.AutoFit Cells.EntireRow.Hidden = False Range("A1").ClearContents Range("A1").Select Next w 'Sauve et ferme Workbooks(NomArch & ".xls").Save Workbooks(NomArch & ".xls").Close Line1: Next K 'Retour à Archives Windows(Fichier).Activate Sheets("Data").Range("AS15").Value = 0 Sheets("Archives").Range("IT4:IT" & Last).ClearContents Last = Sheets("Archives").Range("A65536").End(xlUp).Row Sheets("Archives").Unprotect Sheets("Archives").Range("A4:A" & Last).Font.Bold = False Sheets("Archives").Range("A4:A" & Last).Font.ColorIndex = 0 ActiveWindow.DisplayHeadings = False Sheets("Archives").Range("A" & Range("A65536").End(xlUp).Row + 1).Select Sheets("Data").Range("AS15").Value = 0 Sheets("Archives").Protect _ DrawingObjects:=True, _ Contents:=True, _ Scenarios:=True, _ AllowFiltering:=True End If End Sub
Dans une feuille protégée et seule visible, "Archives", l'utilisateur clique sur une cellule quelconque d'un ligne, ce qui provoque la mise en gras et rouge du texte dans la première cellule de la ligne.
S'il reclique sur cette ligne, la première cellule repasse au format standard.
L'utilisateur doit pouvoir évidemment , avec le mêmes conséquences, faire une sélection 'continue", avec un clic + glisser.
Toutes les lignes dont le texte de la première cellule est Rouge + gras forment une "Sélection", qui sera "Exportée", ligne par ligne après action sur un bouton "Exporter".
Private Sub Workbook_Open()et
Private Sub Workbook_BeforeClose(Cancel As Boolean)assurent un Reset complet, feuille Archive comprise.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit Private sele As Range, corr As Range, prepare As Boolean Private Sub CommandButton1_Click() If CommandButton1.Caption = "Préparer sélections" Then CommandButton1.Caption = "terminer sélections" prepare = True Else CommandButton1.Caption = "Préparer sélections" prepare = False End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) If prepare Then If sele Is Nothing Then ajout Target: Exit Sub If Intersect(Target, sele) Is Nothing Then ajout Target: Exit Sub If Not Intersect(Target, sele) Is Nothing Then Dim r As Range For Each r In Target.Rows If Intersect(r, sele) Is Nothing Then ajout r Else enleve r End If Next End If End If End Sub Private Sub ajout(t As Range) Dim r As Range For Each r In t.Rows Range("A" & r.Row).Interior.Color = vbRed r.EntireRow.Font.Bold = True If sele Is Nothing Then Set sele = r.EntireRow Else Set sele = Union(sele, r.EntireRow) End If Next End Sub Private Sub enleve(t As Range) Set corr = Nothing Dim r As Range For Each r In sele.Rows If Intersect(t, r) Is Nothing Then If corr Is Nothing Then Set corr = r Else Set corr = Union(corr, r) End If Else Range("A" & r.Row).Interior.ColorIndex = xlNone r.EntireRow.Font.Bold = False End If Next If Not corr Is Nothing Then Set sele = corr End Sub
Dans une feuille protégée et seule visible, "Archives", l'utilisateur clique sur une cellule quelconque d'un ligne, ce qui provoque la mise en gras et rouge du texte dans la première cellule de la ligne.
S'il reclique sur cette ligne, la première cellule repasse au format standard.
L'utilisateur doit pouvoir évidemment , avec le mêmes conséquences, faire une sélection 'continue", avec un clic + glisser.
Un clic sur une ligne = Sélection (1ère cellule en Rouge + gras)
Si ligne recliquée= Désélection (1ère cellule repasse en standard)
Ces raccourcis clavier ne sont pas toujours connus des utilisateurs Lamba.
Pour eux, un simple clic sur une ligne est quand même plus convivial, non?
on se place dans la première cellule de la ligne et on appuie simultanément
CTRL, MAJ et flèhce droite
on se place dans la première cellule de la ligne et on appuie simultanément
CTRL, MAJ et flèhce droite
si l'utilisateur revient sur une sélection déjà faite et continue par glisser, la sélection déjà faite est annulée et les autres ajoutées
L'utilisateur doit pouvoir évidemment , avec le mêmes conséquences , faire une sélection "continue", avec un clic + glisser.
'Pour EXPORTER une ou plusieurs Archives If Sheets("Archives").TestAction.Caption = "EXPORTER" Then For Each cell In Selection '========================= If Sheets("Archives").Range("A" & cell.Row).Font.ColorIndex <> 3 Then Sheets("Archives").Range("A" & cell.Row).Font.Bold = True Sheets("Archives").Range("A" & cell.Row).Font.ColorIndex = 3 'Reprise de l'info Row d'une sélection Sheets("Archives").Range("IT" & cell.Row).Value = cell.Row Else Sheets("Archives").Range("A" & cell.Row).Font.Bold = False Sheets("Archives").Range("A" & cell.Row).Font.ColorIndex = 0 Sheets("Archives").Range("IT" & cell.Row).Value = "" End If Next
'Reprise des lignes sélectionnées Range("4:4,6:6,8:8").Select
Option Explicit Private sele As Range, corr As Range, prepare As Boolean Private Sub CommandButton1_Click() If CommandButton1.Caption = "Préparer sélections" Then CommandButton1.Caption = "terminer sélections" prepare = True Else CommandButton1.Caption = "Préparer sélections" prepare = False End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) If prepare Then If sele Is Nothing Then ajout Target: Exit Sub If Intersect(Target, sele) Is Nothing Then ajout Target: Exit Sub If Not Intersect(Target, sele) Is Nothing Then Dim r As Range For Each r In Target.Rows If Intersect(r, sele) Is Nothing Then ajout r Else enleve r End If Next End If End If End Sub Private Sub ajout(t As Range) Dim r As Range 'rajout pour MsgBox Dim ra As String, rs As String, rt As String For Each r In t.Rows 'rajout pour MsgBox If ra "" Then ra "Aucun" Else ra = r.Address If rt "" Then rt "Aucun" Else rt = t.Address Range("A" & r.Row).Font.ColorIndex = 3 Range("A" & r.Row).Font.Bold = True If sele Is Nothing Then Set sele = r.EntireRow Else Set sele = Union(sele, r.EntireRow) End If 'rajout pour MsgBox If rs "" Then rs "Aucun" Else rs = sele.Address MsgBox "Ajoute" & vbNewLine & _ "row " & ra & vbNewLine & _ "sele " & rs & vbNewLine & _ "t " & rt & vbNewLine Next 'Plage sélectionnée ? MsgBox "Corr = " & rs End Sub Private Sub enleve(t As Range) Set corr = Nothing Dim r As Range 'rajout pour MsgBox Dim ra As String, rs As String, rt As String, rc As String If rt "" Then rt "Aucun" Else rt = t.Address For Each r In sele.Rows 'rajout pour MsgBox If ra "" Then ra "Aucun" Else ra = r.Address If rs "" Then rs "Aucun" Else rs = sele.Address If Intersect(t, r) Is Nothing Then If corr Is Nothing Then Set corr = r Else Set corr = Union(corr, r) End If Else Range("A" & r.Row).Font.ColorIndex = 0 Range("A" & r.Row).EntireRow.Font.Bold = False End If 'rajout pour MsgBox If rc "" Then rc "Aucun" Else rc = corr.Address MsgBox "Enlève" & vbNewLine & _ "row " & ra & vbNewLine & _ "sele " & rs & vbNewLine & _ "t " & rt & vbNewLine & _ "corr " & rc Next If Not corr Is Nothing Then Set sele = corr 'Plage sélectionnée ? MsgBox "Corr = " & rc End Sub
...
....
Else
CommandButton1.Caption = "Préparer sélections"
prepare = False
msgbox sele.address ' <<<<======= c'est ici que tu le verras
End If
....
Option Explicit Private sele As String, prepare As Boolean Private Sub CommandButton1_Click() If CommandButton1.Caption = "Préparer sélections" Then CommandButton1.Caption = "terminer sélections" prepare = True Else CommandButton1.Caption = "Préparer sélections" prepare = False Dim decision As Integer decision = MsgBox("voilà les lignes actuellement contenues dans sele : " & vbCrLf & Replace(sele, "@", " ") & vbCrLf & _ "voulez-vous continuer (oui garder la sélection et continuer à sélectionner - non tout effacer et reprendre à zéro)", vbYesNo) If decision = vbNo Then Dim e For Each e In Split(sele, "@") If e <> "" Then Range("A" & e).Interior.Color = xlNone Range("A" & e).EntireRow.Font.Bold = False sele = "" End If Next End If End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) If prepare Then traitons Target End Sub Private Sub traitons(t As Range) Dim r As Range, tut As String For Each r In t.Rows If sele "" Then tut "@" Else tut = "" Select Case Range("A" & r.Row).Interior.Color Case vbRed Range("A" & r.Row).Interior.Color = xlNone r.EntireRow.Font.Bold = False sele = Replace(sele, "@" & r.Row, "") Case Else Range("A" & r.Row).Interior.Color = vbRed r.EntireRow.Font.Bold = True sele = sele & tut & r.Row & "@" End Select Next CommandButton1.Top = Cells(Mid(t.AddressLocal, InStrRev(t.AddressLocal, "$") + 1), t.Column).Top CommandButton1.Left = Cells(t.Row, t.Column + t.Columns.Count).Left End Sub
If Not Intersect(Target, Rows(1)) Is Nothing Then Exit Sub If Not Intersect(Target, Rows(2)) Is Nothing Then Exit Sub If ActiveCell.Value = "" Then Exit Sub
Set sele = Nothing
If Intersect(Target, sele) Is Nothing Then ajout Target: Exit Sub
5) selection sur ligne 7 => Pas de changement de format
8) clic sur Terminer => Préparer = > Ligne 7 pas indiquée dans MsgBox