Simplifier macro pour saut de colonnes

thespeedy20

XLDnaute Occasionnel
Bonjour,

Voici mon code, y a t il moyen de le simplifier, c'est le même traitement sur une plage de la colonne 4 et 11 , j'ai du faire 2 boucles...


VB:
Cells(11, 4).Value = Cells(9, 12).Value - Cells(11, 3).Value
 
  For i = 12 To 30
 
   If Cells(i - 1, 3).Value <> "" Then Cells(i, 4).Value = Cells(i - 1, 4).Value - Cells(i, 3).Value
  
       If Cells(i - 1, 3).Value = "" Then Exit For
  If Cells(i, 3).Value = "" Then Cells(i, 4).Value = ""
 
      
      Next i
    
 
Cells(11, 11).Value = Cells(30, 4).Value - Cells(11, 10).Value
   If Cells(11, 11) = 0 Then Cells(11, 11) = ""
    
  For j = 12 To 30
      
      
    If Cells(j - 1, 10).Value <> "" Then Cells(j, 11).Value = Cells(j - 1, 11).Value - Cells(j, 10).Value
    
       If Cells(j - 1, 10).Value = "" Then Exit For
 If Cells(j, 10).Value = "" Then Cells(j, 11).Value = ""
 
      Next j


Merci d'avance

Oli
 

Robert

XLDnaute Barbatruc
Repose en paix
Bonjour TheSpeedy, bonjour le forum,

Peut-être comme ça :

VB:
Sub Macro1()
Dim COL As Byte
Dim N As Byte
Dim I As Byte

Cells(11, 4).Value = Cells(9, 12).Value - Cells(11, 3).Value
Cells(11, 11).Value = Cells(30, 4).Value - Cells(11, 10).Value
COL = 4
For N = 1 To 2
    For I = 12 To 30
        If Cells(I - 1, COL - 1).Value <> "" Then Cells(I, COL).Value = Cells(I - 1, COL).Value - Cells(I, COL - 1).Value
        If Cells(I - 1, COL - 1).Value = "" Then Exit For
        If Cells(I, COL - 1).Value = "" Then Cells(I, COL).Value = ""
    Next I
    COL = 11
Next N
End Sub
 

Statistiques des forums

Discussions
312 202
Messages
2 086 177
Membres
103 152
dernier inscrit
Karibu