Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CheckUnexpectedABCombinations()
- Dim wsVisits As Worksheet
- Dim wsFlags As Worksheet
- Dim ws As Worksheet
- Dim dictVisits As Object
- Dim lastRow As Long, i As Long
- Dim key As String
- Dim outputRow As Long
- ' Associer l'onglet "visits"
- On Error Resume Next
- Set wsVisits = ThisWorkbook.Worksheets("visits")
- If wsVisits Is Nothing Then
- MsgBox "L'onglet 'visits' est introuvable. Veuillez vérifier.", vbExclamation
- Exit Sub
- End If
- On Error GoTo 0
- ' Créer un dictionnaire pour stocker les combinaisons AB de l'onglet "visits"
- Set dictVisits = CreateObject("Scripting.Dictionary")
- lastRow = wsVisits.Cells(wsVisits.Rows.Count, "A").End(xlUp).Row
- For i = 2 To lastRow ' Commencer à la ligne 2 pour ignorer les en-têtes
- key = wsVisits.Cells(i, "A").Value & "|" & wsVisits.Cells(i, "B").Value
- If Not dictVisits.exists(key) Then
- dictVisits.Add key, True
- End If
- Next i
- ' Créer ou réinitialiser l'onglet "flags"
- On Error Resume Next
- Application.DisplayAlerts = False
- Set wsFlags = ThisWorkbook.Worksheets("flags")
- If Not wsFlags Is Nothing Then wsFlags.Delete
- Application.DisplayAlerts = True
- Set wsFlags = ThisWorkbook.Worksheets.Add
- wsFlags.Name = "flags"
- On Error GoTo 0
- ' Ajouter des en-têtes à l'onglet "flags"
- wsFlags.Cells(1, 1).Value = "Onglet"
- wsFlags.Cells(1, 2).Value = "Ligne"
- wsFlags.Cells(1, 3).Value = "Colonne A"
- wsFlags.Cells(1, 4).Value = "Colonne B"
- outputRow = 2
- ' Parcourir tous les onglets sauf "visits" et "flags"
- For Each ws In ThisWorkbook.Worksheets
- If ws.Name <> "visits" And ws.Name <> "flags" Then
- lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
- For i = 2 To lastRow ' Commencer à la ligne 2 pour ignorer les en-têtes
- key = ws.Cells(i, "A").Value & "|" & ws.Cells(i, "B").Value
- If Not dictVisits.exists(key) Then
- ' Ajouter la ligne dans l'onglet "flags"
- wsFlags.Cells(outputRow, 1).Value = ws.Name
- wsFlags.Cells(outputRow, 2).Value = i
- wsFlags.Cells(outputRow, 3).Value = ws.Cells(i, "A").Value
- wsFlags.Cells(outputRow, 4).Value = ws.Cells(i, "B").Value
- outputRow = outputRow + 1
- End If
- Next i
- End If
- Next ws
- MsgBox "Vérification terminée. Résultats dans l'onglet 'flags'.", vbInformation
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement