[Résolu] Eviter de recopier une ligne

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Lone-wolf

XLDnaute Barbatruc
Bonjour à tous et très bon dimanche,

j'ai un problème avec la macro suivante. En activant la cellule de la colonne F, la macro me recopie la ligne des titre, hors j'aimerais éviter celà si c'est possible.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Sheets(1).Activate
If Not Intersect(Target, Range("a2:f65000")) Is Nothing Then
On Error Resume Next
With ActiveCell.EntireRow
If ActiveCell = Range("f:f") Then: ActiveCell.ClearContents: Range("g1:p65000").ClearContents
If ActiveCell = "" Then              'On commence la saisie en colonne A
Range("a1:f1").Copy ActiveCell
.Font.Bold = False
.Font.Color = RGB(216, 216, 216)
.HorizontalAlignment = xlLeft
Else
Target.Font.Color = RGB(0, 0, 0)
Range("d2:d65000").HorizontalAlignment = xlRight
End If
End With
End If
Application.EnableEvents = True

End Sub


A+ 😎
 

Pièces jointes

Dernière édition:
Re : Eviter de recopier une ligne

Bonjour Gareth,

si tu ouvre le fichier, tu comprendra mieux le problème, en activant la dernière cellule vide de la colonne A. 😉


Edit: la ligne " If ActiveCell = Range("f:f") Then: ActiveCell.ClearContents: Range("g1, p65000").ClearContents " est de trop.



A+ 😎
 
Dernière édition:
Re : Eviter de recopier une ligne

Re Gareth,

J'ai trouvé une solution:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets(1).Activate
If Not Intersect(Target, Range("a2:f65000")) Is Nothing Then
ColMin = Selection.Columns(1).Column
ColMax = Selection.Columns.Count + ColMin - 1
If ColMax = 6 Then Exit Sub
On Error Resume Next
With ActiveCell.EntireRow
If ActiveCell = "" Then
Range("a1:f1").Copy ActiveCell
.Font.Bold = False
.Font.Color = RGB(216, 216, 216)
.HorizontalAlignment = xlLeft
Else
Target.Font.Color = RGB(0, 0, 0)
Range("d2:d65000").HorizontalAlignment = xlRight
End If
End With
End If
End Sub


A+ :cool:
 
Re : Eviter de recopier une ligne

Re Gareth,

effectivement ce n'est pas la bonne solution, et j'aissaie de résoudre le problème tant bien que mal.

Cependant, je ne sais pas ce qu'il faut faire

Et bien, il ne faut pas que la macro recopie la ligne si je sélectionne les cellules à partir de la colonne F.
Je ne sais pas si je me suis bien exprimé.

A+ 😎
 
Re : Eviter de recopier une ligne

Cette fois c'est ok,

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets(1).Activate
If Not Intersect(Target, Range("a2:f65000")) Is Nothing Then
If Not Intersect(Target, Range("f2:f65000")) Is Nothing Then: Target.Font.Color = RGB(0, 0, 0): Exit Sub

With ActiveCell.EntireRow
If ActiveCell = "" Then
Range("a1:g1").Copy ActiveCell
.Font.Bold = False
.Font.Color = RGB(216, 216, 216)
.HorizontalAlignment = xlLeft
Else
Target.Font.Color = RGB(0, 0, 0)
Range("d2:d65000").HorizontalAlignment = xlRight
End If
End With
End If
End Sub


A+ 😎
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
5
Affichages
910
  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
1 K
  • Question Question
Microsoft 365 Probléme VBA
Réponses
8
Affichages
588
Retour