un internaute
XLDnaute Impliqué
Bonjour le forum,
Dans la feuille Janvier 2018 j'ai la macro ci-dessous qui centre sur colonnes H - I:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sh As Shape
If Target.Count = 1 Then
Set sh = ActiveSheet.Shapes("Centrage")
ActiveSheet.Unprotect
With sh.TextFrame
If (Range("H" & Target.Row) <> "" And Range("I" & Target.Row) <> "") Or _
(Range("H" & Target.Row) = "" And Range("I" & Target.Row) = "") Then
.Characters.Text = "Aucune Action Possible"
ElseIf Range("H" & Target.Row).HorizontalAlignment = xlCenterAcrossSelection Then
.Characters.Text = "Annuler Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=28, Length:=22).Font.ColorIndex = 5
ElseIf (Range("H" & Target.Row) <> "" And Range("I" & Target.Row) = "") Or _
(Range("H" & Target.Row) = "" And Range("I" & Target.Row) <> "") Then
.Characters.Text = "Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=15, Length:=22).Font.ColorIndex = 5
End If
End With
'ActiveSheet.Protect
End If
End Sub
Dans macro CentrerTexte celle ci-dessous qui centre sur colonnes H - I :
Sub CentrerTexte()
Dim Ligne As Long
Dim Ws As Worksheet
Dim sh As Shape
Dim Nom As String
Dim ModeCentrage As Integer
Application.ScreenUpdating = False
Set sh = ActiveSheet.Shapes(Application.Caller)
If UCase(Left(sh.TextFrame.Characters.Text, 6)) = UCase("Aucune") Then Exit Sub 'If UCase(Left(Sh.Characters.Text, 6)) = UCase("Aucune") Then Exit Sub
ActiveSheet.Unprotect
With sh.TextFrame
'On compare les 7 caractères de gauche(Left)en Majuscule(UCase)du Texte du bouton avec les caractères en Majuscule(UCase)du mot "Centrer".
If UCase(Left(.Characters.Text, 7)) = UCase("Centrer") Then
.Characters.Text = "Annuler Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=23, Length:=22).Font.ColorIndex = 5
ModeCentrage = xlCenterAcrossSelection
Else
.Characters.Text = "Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=15, Length:=22).Font.ColorIndex = 5
ModeCentrage = xlCenter
End If
End With
Ligne = Selection.Row
With Range("H" & Ligne & ":I" & Ligne)
.HorizontalAlignment = ModeCentrage
.VerticalAlignment = xlCenter
End With
ActiveSheet.Protect
End Sub
Ma question est la suivante:
Peut - on regrouper dans la même macro pour faire centrer sur?
Colonnes C - F
Colonnes C - D
Colonnes E - F
Merci pour vos éventuels retours
Bon dimanche à tous
Cordialement
Dans la feuille Janvier 2018 j'ai la macro ci-dessous qui centre sur colonnes H - I:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sh As Shape
If Target.Count = 1 Then
Set sh = ActiveSheet.Shapes("Centrage")
ActiveSheet.Unprotect
With sh.TextFrame
If (Range("H" & Target.Row) <> "" And Range("I" & Target.Row) <> "") Or _
(Range("H" & Target.Row) = "" And Range("I" & Target.Row) = "") Then
.Characters.Text = "Aucune Action Possible"
ElseIf Range("H" & Target.Row).HorizontalAlignment = xlCenterAcrossSelection Then
.Characters.Text = "Annuler Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=28, Length:=22).Font.ColorIndex = 5
ElseIf (Range("H" & Target.Row) <> "" And Range("I" & Target.Row) = "") Or _
(Range("H" & Target.Row) = "" And Range("I" & Target.Row) <> "") Then
.Characters.Text = "Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=15, Length:=22).Font.ColorIndex = 5
End If
End With
'ActiveSheet.Protect
End If
End Sub
Dans macro CentrerTexte celle ci-dessous qui centre sur colonnes H - I :
Sub CentrerTexte()
Dim Ligne As Long
Dim Ws As Worksheet
Dim sh As Shape
Dim Nom As String
Dim ModeCentrage As Integer
Application.ScreenUpdating = False
Set sh = ActiveSheet.Shapes(Application.Caller)
If UCase(Left(sh.TextFrame.Characters.Text, 6)) = UCase("Aucune") Then Exit Sub 'If UCase(Left(Sh.Characters.Text, 6)) = UCase("Aucune") Then Exit Sub
ActiveSheet.Unprotect
With sh.TextFrame
'On compare les 7 caractères de gauche(Left)en Majuscule(UCase)du Texte du bouton avec les caractères en Majuscule(UCase)du mot "Centrer".
If UCase(Left(.Characters.Text, 7)) = UCase("Centrer") Then
.Characters.Text = "Annuler Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=23, Length:=22).Font.ColorIndex = 5
ModeCentrage = xlCenterAcrossSelection
Else
.Characters.Text = "Centrer Texte" & vbLf & "Sur Plusieurs Colonnes"
.Characters(Start:=15, Length:=22).Font.ColorIndex = 5
ModeCentrage = xlCenter
End If
End With
Ligne = Selection.Row
With Range("H" & Ligne & ":I" & Ligne)
.HorizontalAlignment = ModeCentrage
.VerticalAlignment = xlCenter
End With
ActiveSheet.Protect
End Sub
Ma question est la suivante:
Peut - on regrouper dans la même macro pour faire centrer sur?
Colonnes C - F
Colonnes C - D
Colonnes E - F
Merci pour vos éventuels retours
Bon dimanche à tous
Cordialement