Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

limitation d'usage d'une macro à une plage donnée

4 réponses
Avatar
Christian de BXL
Bonjour à tous,
Comment puis-je limiter l'usage d'une macro à une plage de cellules donnée.
Je voudrais que la macro "ZAZA" ne soit utilisable que que si la cellule
active se trouve dans la plage A3 A25.
Comment faire également si ces cellules sont nommées?
Merci à vous
Christian

4 réponses

Avatar
Daniel.C
Bonjour.
Utilise le code suivant :

If Intersect(ActiveCell, [A3:A25]) Is Nothing Then Exit Sub
ou
Set Plage = [A3:A25]
If Intersect(ActiveCell, Plage) Is Nothing Then Exit Sub

Cordialement.
Daniel
"Christian de BXL" a écrit dans
le message de news:
Bonjour à tous,
Comment puis-je limiter l'usage d'une macro à une plage de cellules
donnée.
Je voudrais que la macro "ZAZA" ne soit utilisable que que si la cellule
active se trouve dans la plage A3 A25.
Comment faire également si ces cellules sont nommées?
Merci à vous
Christian


Avatar
Christian de BXL
Bonsoir Daniel,
Merci pour ton aide, mais où dois-je mettre ces lignes dans ma macro servant
à renvoyer automatiquement un un texte à la ligne dans des cellules
fusionnées:

Private Sub Worksheet_Change(ByVal Target As Range)
'Jim Rech, mpep

Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim targetWidth As Single, PossNewRowHeight As Single

If Target.MergeCells Then
With Target.MergeArea
.WrapText = True 'enclenche le renvoi à la ligne automatique (modif
fs)
If .Rows.Count = 1 Then 'And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
targetWidth = Target.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + _
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = targetWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If

End Sub

Dans le cas ou la référence de mes cellules est variables, je pourrais
nommer la cellule de début et la cellule de fin de plage. Comment intégrer
ces noms? En remplaçant les coordonnées de cellules par ceux-ci ou faut-il
leur ajouter un signe quelconque?
Merci à toi
Christian
Avatar
Daniel.C
Bonsoir.

Private Sub Worksheet_Change(ByVal Target As Range)
'Jim Rech, mpep

Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim targetWidth As Single, PossNewRowHeight As Single

'****** Là
If Intersect(Target, [A3:A25]) Is Nothing Then Exit Sub
'******

If Target.MergeCells Then
With Target.MergeArea
.WrapText = True 'enclenche le renvoi à la ligne automatique (modif
fs)
If .Rows.Count = 1 Then 'And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
targetWidth = Target.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + _
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = targetWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If

End Sub

Daniel

"Christian de BXL" a écrit dans
le message de news:

Bonsoir Daniel,
Merci pour ton aide, mais où dois-je mettre ces lignes dans ma macro
servant
à renvoyer automatiquement un un texte à la ligne dans des cellules
fusionnées:

Private Sub Worksheet_Change(ByVal Target As Range)
'Jim Rech, mpep

Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim targetWidth As Single, PossNewRowHeight As Single

If Target.MergeCells Then
With Target.MergeArea
.WrapText = True 'enclenche le renvoi à la ligne automatique (modif
fs)
If .Rows.Count = 1 Then 'And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
targetWidth = Target.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + _
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = targetWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If

End Sub

Dans le cas ou la référence de mes cellules est variables, je pourrais
nommer la cellule de début et la cellule de fin de plage. Comment intégrer
ces noms? En remplaçant les coordonnées de cellules par ceux-ci ou faut-il
leur ajouter un signe quelconque?
Merci à toi
Christian


Avatar
Christian de BXL
Merci à toi Daniel, je vais essayer de tester cela ce WE.
A bientôt
Christian