J'ai cette macro
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim x As Integer Dim S1 As Ssortingng Dim S2 As Ssortingng S1 = "Football" S2 = "Basket" x = 1 Do If IsEmpty(Cells(x, 5)) And ((Cells(x, 3) = S1) Or (Cells(x, 3) = S2)) Then MsgBox "Insert a value in the empty cell" Cancel = True End If x = x + 1 Loop Until Cells(x, 1) = "" End Sub
Lorsque je clique sur le button "x" pour fermer la feuille si la colonne 5 est vide et que la colonne 3 contient Football
ou Basket
la macro effectue un contrôle et apparaît une boîte de message pour avertir que vous avez inséré une valeur. La vérification va mais je ne sais pas que MsgBox
apparaît 16 fois et non 1. Pourquoi?
Mettre mes commentaires dans une réponse. Ajoutant plus de choses également.
LONG
sheet1
mais sheet2
est active lorsque vous fermez le classur, vous n'obtiendrez pas les résultats souhaités MsgBox
plus significatif. Comment l'user sait quelle cellule est vide 🙂 Est-ce ce que vous essayez? ( NON TESTÉ )
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Private Sub Workbook_BeforeClose (Annuler comme boolean)Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Dim S1 As Ssortingng, S2 comme stringPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Dim lRow As Long, i As LongPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Dim ws As WorksheetPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Définir ws = ThisWorkbook.Sheets ("Sheet1")Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
S1 = "Football": S2 = "Panier"Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Avec wsPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
'~~> Trouver la dernière ligne qui contient des donnéesPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
'~ ~> on bouclera jusqu'à présentPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
lRow = .Range ("A" et .Rows.Count) .End (xlUp) .RowPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Pour i = 1 à lRowPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Si Len (Trim (.Range ("E" & i) .Value)) = 0 ThenPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Sélectionnez Case .Range ("C" & i) .ValuePrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Cas S1, S2Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
'~~> Dites à l'user quelle cellule est videPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
MsgBox "Insérer une valeur dans la cellule" & _Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
.Range ("E" & i). AdressePrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Annuler = VraiPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
'~~> Quittez la boucle après le premier matchPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Sortie pourPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub
Fin ChoisirPrivate Sub Workbook_BeforeClose(Cancel As Boolean) Dim S1 As Ssortingng, S2 As Ssortingng Dim lRow As Long, i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") S1 = "Football": S2 = "Basket" With ws '~~> Find the last row which has data '~~> we will loop till there lRow = .Range("A" & .Rows.Count).End(xlUp).Row For i = 1 To lRow If Len(Trim(.Range("E" & i).Value)) = 0 Then Select Case .Range("C" & i).Value Case S1, S2 '~~> Tell user which cell is empty MsgBox "Insert a value in the cell " & _ .Range("E" & i).Address Cancel = True '~~> Exit the loop after the first match Exit For End Select End If Next i End With End Sub