Relier deux codes VBA

Bonjour

Je souhaiterais savoir comment je dois faire pour relier ces deux codes. Ecrire les cellules d'une colonne toujours en majuscule et idem en minuscules pour une autre colonne.

Merci

Cdlt

TA

Private Sub Worksheet_Change(ByVal Target As Range)

With Target

If .Count > 1 Then Exit Sub

If Intersect(Target, Range("B8:B500")) Is Nothing Then Exit Sub

Application.EnableEvents = False

.Value = UCase$(.Value)

With .Font

.Size = 16: .Bold = True

Application.EnableEvents = True

End With

End With

XXXXXXXXXXXXXX

If Intersect(Target, Range("c8:c500")) Is Nothing Then Exit Sub

Application.EnableEvents = False

.Value = LCase$(.Value)

With .Font

.Size = 16

Application.EnableEvents = True

End With

End With

End Sub

Salut Tacentaure,

quelque chose comme ça?

Private Sub Worksheet_Change(ByVal Target As Range)
'
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
'
If Not Intersect(Target, Range("B8:C500")) Is Nothing Then
    Target = IIf(Target.Column = 2, UCase(Target), LCase(Target))
    Target.Font.Bold = IIf(Target.Column = 2, True, False)
    Target.Font.Size = 16
End If
'
Application.EnableEvents = True
'
End Sub

A+

Salut Steelson!

Bonjour,

edit : bonjour curulis57

indente ton code pour y voir plus clair !

Private Sub Worksheet_Change(ByVal Target As Range)

With Target

    If .Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("B8:B500")) Is Nothing Then
        Application.EnableEvents = False
        .Value = UCase$(.Value)
        With .Font
            .Size = 16: .Bold = True
        End With
        Application.EnableEvents = True

    ElseIf Not Intersect(Target, Range("c8:c500")) Is Nothing Then

        Application.EnableEvents = False
        .Value = LCase$(.Value)
        With .Font
            .Size = 16
        End With
        Application.EnableEvents = True
    End If

End With

End Sub

Le code de curulis57 est plus court et plus intéressant.

Je me suis contenté de te montrer comment "relier" ces 2 codes en évitant les exit sub mais sans l’optimiser).

Rechercher des sujets similaires à "relier deux codes vba"