Microsoft 365 Relier deux code VBA

BERNO

XLDnaute Nouveau
Bonsoir

J'ai un code VBA ( voir ci dessous) qui fonctionne, un deuxième qui seul fonctionne aussi.....a présent j'aimerais les relier pour qu'ils fonctionnent les deux car uniquement le premier fonctionne actuellement

Merci pour l'aide

Berno


Option Explicit
Sub Macro5()
Dim ville$, lig&, col%, ltr$
With ActiveCell
ville = .Value: If ville = "" Then Exit Sub
lig = .Row: If lig < 3 Or lig > 1481 Then Exit Sub
col = .Column: If col <> 5 And col <> 7 And col <> 9 And col <> 11 Then Exit Sub

ltr = Cells(lig, 3): If ltr <> "NUIT" Then Exit Sub
.Offset(4) = ville: If lig <= 1481 Then .Offset(9) = ville
If lig <= 1481 Then .Offset(13) = ville
If lig <= 1481 Then .Offset(18) = ville
If lig <= 1481 Then .Offset(22) = ville

' Deuxième code

ltr = Cells(lig, 3): If ltr <> "MATIN" Then Exit Sub
.Offset(4) = ville: If lig <= 1481 Then .Offset(9) = ville
If lig <= 1481 Then .Offset(13) = ville


End With

End Sub

••••ˇˇˇˇ
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonsoir Berno,
En modifiant vos IF,
If =Nuit
Action si Nuit
Else if = Matin
Action Matin
End If

VB:
Option Explicit
Sub Macro5()
Dim ville$, lig&, col%, ltr$
With ActiveCell
ville = .Value: If ville = "" Then Exit Sub
lig = .Row: If lig < 3 Or lig > 1481 Then Exit Sub
col = .Column: If col <> 5 And col <> 7 And col <> 9 And col <> 11 Then Exit Sub

ltr = Cells(lig, 3)
If ltr = "NUIT" Then
   .Offset(4) = ville: If lig <= 1481 Then .Offset(9) = ville
   If lig <= 1481 Then .Offset(13) = ville
   If lig <= 1481 Then .Offset(18) = ville
   If lig <= 1481 Then .Offset(22) = ville
Else If ltr = "MATIN" Then
   .Offset(4) = ville: If lig <= 1481 Then .Offset(9) = ville
   If lig <= 1481 Then .Offset(13) = ville
END If
End With
End Sub

A tester.
 

Discussions similaires

Réponses
25
Affichages
801