Simplification code VBA

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 !

TheProdigy

XLDnaute Impliqué
Bonjour à tous.

Quelqu'un pourrait me suggérer un code plus rapide.

Code:
If Sheets("repmamda").Range("V1").Value <> Sheets("repmamda").Range("W1").Value Then
'si difference changement de V1 et W1
' qui entrainera les changements en D8 C8 D7 C7

For N = 1 To 41
 Sheets("repmamda").Range("V" & N) = Sheets("repmamda").Range("W" & N)
 Sheets("repmamda").Range("X" & N) = Sheets("repmamda").Range("Y" & N)
 Sheets("repmcma").Range("V" & N) = Sheets("repmcma").Range("W" & N)
 Sheets("repmcma").Range("X" & N) = Sheets("repmcma").Range("Y" & N)
Next N
  Sheets("M_prtf").Range("a1") = Sheets("mcma").Range("i2")
  Sheets("Suivi PLV").Range("a1") = Sheets("mcma").Range("i2")
  
End If

Merci
 
Re : Simplification code VBA

Bonjour,

Plus rapide pas tellement mais c'est plus clair :

Code:
For N = 1 To 41
With Sheets("repmamda")
 .Range("V" & N) = .Range("W" & N)
 .Range("X" & N) = .Range("Y" & N)
End With
With Sheets("repmcma")
 .Range("V" & N) = .Range("W" & N)
 .Range("X" & N) = .Range("Y" & N)
End With
Next N
x = Sheets("mcma").Range("i2").Value
Sheets("M_prtf").Range("a1") = x
Sheets("Suivi PLV").Range("a1") = x

A+
 
Dernière édition:
Re : Simplification code VBA

Bonsoir,

A tester :

Sub test()
If Sheets("repmamda").Range("V1").Value <> Sheets("repmamda").Range("W1").Value Then
Debut = 1
Fin = 41
With Sheets("repmamda")
.Range("V" & Debut & ":V" & Fin).Copy .Range("W" & Debut)
.Range("X" & Debut & ":V" & Fin).Copy .Range("Y" & Debut)
End With
With Sheets("repmcma")
.Range("V" & Debut & ":V" & Fin).Copy .Range("W" & Debut)
.Range("X" & Debut & ":V" & Fin).Copy .Range("Y" & Debut)
End With
Sheets("M_prtf").Range("a1") = Sheets("mcma").Range("i2")
Sheets("Suivi PLV").Range("a1") = Sheets("mcma").Range("i2")
End If
End Sub
 
Re : Simplification code VBA

Bonsoir adilprodigy, job75, Catrice, le Forum,

Encore un autre point de vue...
Code:
    [COLOR=NAVY]If[/COLOR] .Range("V1").Value <> .Range("W1").Value [COLOR=NAVY]Then[/COLOR]
        
        [COLOR=NAVY]With[/COLOR] Sheets("repmamda")
            .Range("V1:V41").Value = .Range("W1:W41").Value
            .Range("X1:X41").Value = .Range("Y1:Y41").Value
        [COLOR=NAVY]End With[/COLOR]
        
        [COLOR=NAVY]With[/COLOR] Sheets("repmcma")
            .Range("V1:V41").Value = .Range("W1:W41").Value
            .Range("X1:X41").Value = .Range("Y1:Y41").Value
        [COLOR=NAVY]End With[/COLOR]
        
        [COLOR=NAVY]With[/COLOR] Sheets("mcma").Range("i2")
            Sheets("M_prtf").Range("a1").Value = .Value
            Sheets("Suivi PLV").Range("a1").Value = .Value
        [COLOR=NAVY]End With[/COLOR]
      
    [COLOR=NAVY]End If[/COLOR]
Cordialement,
 
Re : Simplification code VBA

Est ce que la solution suivante est plus rapide? Merci
Code:
'' solution plus rapide que la boucle
  'Dim tablo1 As Variant
  ''remplissage du tableau avec les valeurs de la plage ...
  'tablo1 = [repmamda!W1:W41]
  ''remplissage de la plage avec les valeurs du tableau
  '[repmamda!V1:V41] = tablo1
  'tablo1 = [repmamda!Y1:Y41]: [repmadma!X1:X41] = tablo1
  'tablo1 = [repmcma!W1:W41]: [repmcma!V1:V41] = tablo1
  'tablo1 = [repmcma!Y1:Y41]: [repmcma!X1:X41] = tablo1
Merci
 
- 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
10
Affichages
1 K
D
Réponses
4
Affichages
1 K
Dangdang
D
  • Question Question
Microsoft 365 îPb code VBA
Réponses
1
Affichages
671
B
  • Question Question
Réponses
3
Affichages
1 K
Réponses
14
Affichages
882
D
Réponses
4
Affichages
1 K
Retour