For index_ligne = 2 To nb_ligne_max annee = Worksheets("Detail").Cells(index_ligne, index_colonne_annee).Value Reception_initiale = Worksheets("Detail").Cells(index_ligne, index_colonne_reception).Formula Tag = Worksheets("Detail").Cells(index_ligne, index_colonne_categorie).Formula Ratios(1) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio1).Value Ratios(2) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio2).Value Ratios(3) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio3).Value Ratios(4) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio4).Value Ratios(5) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio5).Value Ratios(6) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio6).Value Ratios(7) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio7).Value Ratios(8) = Worksheets("Detail").Cells(index_ligne, index_colonne_ratio8).Value
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Type titi A as ... B as .... .... End Type
pour éclater un certain nombre de lignes (environ 3000)
index_ligne = index_ligne + 1
.....
index_ligne = index_ligne - 1
.........
index_ligne = index_ligne + nb_ratios - 1
For index_ligne = 2 To nb_ligne_max
j'ai bien compris que mon approche à un problème de fond, mais le temps me manque pour renvoir l'ensemble du fichier.
Sub eclatement_par_module(categorie) ' variables Dim Ratios(8) As Single Dim compteur_copies As Byte Dim index_ligne As Integer Dim reception1 As String Dim reception2 As String Dim nb_ligne_max As Integer Dim index_colonne_annee As Byte Dim index_colonne_categorie As Byte Dim index_colonne_reception As Byte Dim index_colonne_ratio(8) As Byte Dim index_colonne_montant As Byte Dim index_colonne_commentaire As Byte Dim Formule As String Dim index_ligne_mere As Integer Dim nb_ratios As Byte Dim ratio As Single Dim i As Byte Dim annee As Integer Dim Reception_initiale As String Dim Tag As String Dim Montant As String ' paramètres reception1 = "reception1 " reception2 = "reception2 " index_colonne_annee = 1 index_colonne_categorie = 11 index_colonne_reception = 2 For i = 1 To 8 index_colonne_ratio(i) = i + 13 Next index_colonne_montant = 34 index_colonne_commentaire = 36 With Worksheets("Detail") ' Recherche de la derniere valeur sur la colonne annee. C'est ici que l'on devrait gagner en temps d'execution ' car la boucle sera limitée au nombre de valeur réel nb_ligne_max = .Cells(.Columns(index_colonne_annee).Rows.Count, index_colonne_annee).End(xlUp).Row ' parcours du tableau For index_ligne = 2 To nb_ligne_max annee = .Cells(index_ligne, index_colonne_annee).Value Reception_initiale = .Cells(index_ligne, index_colonne_reception).Formula Tag = .Cells(index_ligne, index_colonne_categorie).Formula For i = 1 To 8 Ratios(i) = .Cells(index_ligne, index_colonne_ratio(i)).Value Next Montant = .Cells(index_ligne, index_colonne_montant).Value Formule = .Cells(index_ligne, index_colonne_montant).Formula ' ligne qui matche sur l'année de référence : à éclater If Tag categorie And Reception_initiale "reception1" Then ' coloriage de la ligne mère .Cells(index_ligne, index_colonne_reception).Interior.ColorIndex = 22 index_ligne_mere = index_ligne nb_ratios = 0 For index_ratio = 1 To 8 ratio = Ratios(index_ratio) If ratio > 0 Then ' compteur du nombre de ratios non vides nb_ratios = nb_ratios + 1 ' copie de la ligne With .Rows(index_ligne_mere) .Copy .Insert Shift:=xlDown End With 'Application.CutCopyMode = False /!\ ne sert à rien ! ' incrémentation de la ligne pour passer à la ligne copiée index_ligne = index_ligne + 1 'mise à jour de la ligne copiée : ' coloriage .Cells(index_ligne, index_colonne_reception).Interior.ColorIndex = 22 ' nouvelle formule If Left(Formule, 1) Chr(61) Then 'Chr(61) "=" new_formule = Formule & "*" & ratio Else new_formule = "=" & Formule & "*" & ratio End If new_formule = Replace(new_formule, ",", ".") 'pour éviter les problèmes d'incompatibilités de valeurs à décimales .Cells(index_ligne, index_colonne_montant).Formula = new_formule ' reception If index_ratio < 8 Then .Cells(index_ligne, index_colonne_reception).Value = reception2 ' valeurs des taux For i = 1 To 8 If i = index_ratio Then .Cells(index_ligne, index_colonne_ratio(i)).Value = 1 Else .Cells(index_ligne, index_colonne_ratio(i)).ClearContents End If Next i ' commentaires .Cells(index_ligne, index_colonne_commentaire).Text = .Cells(index_ligne, index_colonne_commentaire).Text & " au pro-rata de la contribution à l'offre" ' décrémentation de l'index de ligne pour revenir à la ligne mère index_ligne = index_ligne - 1 End If Next index_ratio ' suppression de la ligne mere et incrémentation de l'index de ligne pour sauter les lignes copiées Rows(index_ligne_mere).Delete Shift:=xlUp index_ligne = index_ligne + nb_ratios - 1 End If Next index_ligne End With End Sub