Compiler plusieurs Codes / Plusieurs alerte
Bonjour,
J'ai un code qui me permets d'avoir un MsgBox 1 mois avant l'expiration de la date de validité de certain documents.
Il est relié uniquement à la colonne "G" Je voudrais le même ou presque pour plusieurs autres colonnes en le gardant sur " Workbook_Open"
Qu'est ce que je peux faire ? y-a-t-il un code qui signifie "ensuite" ? ou y a-t-il un code à exécuter ?
Voilà le code :
Private Sub Workbook_open()
Dim g As Range
Application.ScreenUpdating = False
With Sheets("Feuil1") ' à modifier
For Each g In .Range(.[G3], .[G65536].End(xlUp))
If g.Value < DateSerial(Year(Date), Month(Date) + 1, Day(Date)) Then
If txt = "" Then txt = "Avertissement : Expiration Attestation URSSAF:" & vbCrLf
txt = txt & g.Offset(, -6) & ", " & g.Offset(, -5) & vbCrLf
End If
Next g
If txt <> "" Then MsgBox txt
End With
Application.ScreenUpdating = True
End Sub
Bonjour,
Il te suffit de définir une plage ... celle dont tu as besoin ...
Et ensuite de simplement modifier ton code au niveau de l'instruction
For Each g In .Range(.[G3], .[G65536].End(xlUp))
pour avoir à la place
For Each g In MaPlage
En fait je me suis mal exprimé voilà ce que je voudrais exactement :
Le code marche bien sauf qu'il affiche toujours le MsgBox qui est en gras et souligné. (c'est à dire le premier)
Comment je peux faire pour qu'il affiche les MsgBox propre a chaque partie pour chaque "partie"
pour la colonne G je veux qu'il affiche ça : "Avertissement : Expiration Attestation URSSAF"
pour la colonne Y je veux qu'il affiche ça : "Avertissement : Expiration Extrait Kbis"
pour la colonne AA je veux qu'il affiche ça : "Avertissement : Expiration de la liste des salariés étrangers"
Merci par avance pour ton aide ^^
Voilà le code :
Private Sub Workbook_open()
Dim g As Range
Application.ScreenUpdating = False
With Sheets("Feuil1") ' à modifier
For Each g In .Range(.[G3], .[G65536].End(xlUp))
If g.Value < DateSerial(Year(Date), Month(Date) + 1, Day(Date)) Then
If txt = "" Then txt = "Avertissement : Expiration Attestation URSSAF:" & vbCrLf
txt = txt & g.Offset(, -6) & ", " & g.Offset(, -5) & vbCrLf
End If
Next g
If txt <> "" Then MsgBox txt
End With
Application.ScreenUpdating = True
Application.ScreenUpdating = False
With Sheets("Feuil1") ' à modifier
For Each y In .Range(.[Y3], .[Y65536].End(xlUp))
If y.Value < DateSerial(Year(Date), Month(Date) + 1, Day(Date)) Then
If txt = "" Then txt = "Avertissement : Expiration Extrait Kbis:" & vbCrLf
txt = txt & y.Offset(, -24) & ", " & y.Offset(, -23) & vbCrLf
End If
Next y
If txt <> "" Then MsgBox txt
End With
Application.ScreenUpdating = True
Dim aa As Range
Application.ScreenUpdating = False
With Sheets("Feuil1") ' à modifier
For Each aa In .Range(.[AA3], .[AA65536].End(xlUp))
If aa.Value < DateSerial(Year(Date), Month(Date) + 1, Day(Date)) Then
If txt = "" Then txt = "Avertissement : Expiration de la liste des salariés étrangers:" & vbCrLf
txt = txt & aa.Offset(, -26) & ", " & aa.Offset(, -25) & vbCrLf
End If
Next aa
If txt <> "" Then MsgBox txt
End With
Application.ScreenUpdating = True
End Sub
Re,
Il me semblait bien que cette question allait survenir ...
Te sens-tu capable d'insérer un test sur la colonne ... pour modifier le texte à afficher en conséquence ...???
Le test avec la touche "F8" ? oui je le fais il execute le code sans problème sauf qu'il affiche tjrs le 1er msg.
C'est ce que tu voulais dire ?
Sinon explique moi stp ce que je pourrais éventuellement faire, je pense et j’espère être assez débrouillarde ^^
Noemie.L a écrit :Le test avec la touche "F8" ? oui je le fais il execute le code sans problème sauf qu'il affiche tjrs le 1er msg.
C'est ce que tu voulais dire ?
Sinon explique moi stp ce que je pourrais éventuellement faire, je pense et j’espère être assez débrouillarde ^^
Pardon ... je ne suis pas exprimé très clairement ...
Insérer un test ... cela signifie dans le code, écrire un test
If la colonne est G then
If la colonne est Y then
et enfin la colonne est AA
Voilà le fichier si ça peut t'aider à comprendre mon cas
Re,
Tu peux tester le code suivant ...
Private Sub Workbook_open()
Dim c As Range
Dim plage As Range
Dim txt As String
Set plage = Feuil1.Range("G3:G100,Y3:Y100,AA3:AA100")
Application.ScreenUpdating = False
For Each c In plage
If c.Value <> "" And c.Value < DateSerial(Year(Date), Month(Date) + 1, Day(Date)) Then
Select Case c.Column
Case 7
If txt = "" Then txt = "Avertissement : Expiration Attestation URSSAF:" & vbCrLf
txt = txt & c.Offset(, -6) & ", " & c.Offset(, -5) & vbCrLf
Case 25
If txt = "" Then txt = "Avertissement : Expiration Extrait Kbis:" & vbCrLf
txt = txt & c.Offset(, -24) & ", " & c.Offset(, -23) & vbCrLf
Case 27
If txt = "" Then txt = "Avertissement : Expiration de la liste des salariés étrangers:" & vbCrLf
txt = txt & c.Offset(, -26) & ", " & c.Offset(, -25) & vbCrLf
End Select
End If
Next c
If txt <> "" Then MsgBox txt
Application.ScreenUpdating = True
End Sub
Excellent ! Mrc bcp. Je vais essayer ce code.
Noemie.L a écrit :Excellent ! Mrc bcp. Je vais essayer ce code.
Tiens moi au courant pour savoir si çà joue ... ou pas ...
En fait ce n'est pas vraiment ça. car finalement ça ne fait qu'une seule alerte, et il y a tjrs le soucis de l'intitulé du message. (vu qu'il y a une seule alerte MsgBox).
En fait sur le doc que je t'ai envoyé il fait trois fois l'alerte (comme je veux), sauf qu'il se réfère tjrs au premier intitulé du MsgBox.. et je voudrais qu'il évite ça, qu'il aille a l'intitulé du MsgBox qui correspond
Bonjour,
A force d'être concentré sur la fusion des trois cas ...j'ai complètement oublié de m'occuper du MsgBox ....
Private Sub Workbook_open()
Dim c As Range
Dim plage As Range
Dim txt As String
Set plage = Feuil1.Range("G3:G100,Y3:Y100,AA3:AA100")
Application.ScreenUpdating = False
For Each c In plage
If c.Value <> "" And c.Value < DateSerial(Year(Date), Month(Date) + 1, Day(Date)) Then
Select Case c.Column
Case 7
If txt = "" Then txt = "Avertissement : Expiration Attestation URSSAF:" & vbCrLf
txt = txt & c.Offset(, -6) & ", " & c.Offset(, -5) & vbCrLf
MsgBox txt
Case 25
If txt = "" Then txt = "Avertissement : Expiration Extrait Kbis:" & vbCrLf
txt = txt & c.Offset(, -24) & ", " & c.Offset(, -23) & vbCrLf
MsgBox txt
Case 27
If txt = "" Then txt = "Avertissement : Expiration de la liste des salariés étrangers:" & vbCrLf
txt = txt & c.Offset(, -26) & ", " & c.Offset(, -25) & vbCrLf
MsgBox txt
End Select
End If
Next c
Application.ScreenUpdating = True
End Sub
A tester ... bien sûr ...