Simplification macro
Bonjour à toutes et à tous,
Je viens de créer une macro que je trouve beaucoup trop longue et qui est lourde. Je pense et suis quasiment sûr qu’elle peut être simplifiée. Cependant, je ne sais pas comment.
Tel quel, la macro fonctionne « très bien ». Disons qu’elle me sort ce que je lui demande, mais étant lourde, elle met pas mal de temps à tout mettre en place.
Voici une partie de macro :
Dim Nr_entrepot As String
Nr_site = InputBox("Taper le numéro du site", "Nr_site", "Rentrer le Numéro du site ICI !!!")
Dim i, y As Integer
''Partie 1
For i = 2 To 7000
'
'
'
'Renseignement de l'inventaire production positive
If Nr_site = Worksheets("Inventaire").Cells(i, 2) And (Worksheets("Inventaire").Cells(i, 5) = Worksheets("Base_de_donnees").Range("H2").Value) Then
Cells(2, 1) = "Partie 1"
'Mise en forme titre partie 1
Range("A2:BF2").Select
Call mise_en_forme_ligne_titre
Cells(3 + y, 1) = Worksheets("Inventaire").Cells(i, 1) 'Nom
Cells(3 + y, 2) = Worksheets("Inventaire").Cells(i, 5) 'Type d'installation
Cells(3 + y, 3) = Worksheets("Inventaire").Cells(i, 18) 'CODE
Cells(3 + y, 4) = Worksheets("Inventaire").Cells(i, 7) 'Désignation
Cells(3 + y, 5) = Worksheets("Inventaire").Cells(i, 8) 'Fabricant
Cells(3 + y, 6) = Worksheets("Inventaire").Cells(i, 9) 'Désignation type
Cells(3 + y, 7) = Worksheets("Inventaire").Cells(i, 13) 'Numéro de série
Cells(3 + y, 8) = "" 'Unité
Cells(3 + y, 9).FormulaR1C1 = "=IF(COUNTIF(RC[-6],""*GRP*""),VLOOKUP(RC[-6],TBL_Tarifs!R5C3:R57C28,2,FALSE),"""")"
Cells(3 + y, 11).FormulaR1C1 = "=IF(COUNTIF(RC[-8],""*GRP*""),VLOOKUP(RC[-8],TBL_Tarifs!R5C3:R57C28,3,FALSE),"""")"
Cells(3 + y, 13).FormulaR1C1 = "=IF(COUNTIF(RC[-10],""*GRP*""),VLOOKUP(RC[-10],TBL_Tarifs!R5C3:R57C28,4,FALSE),"""")"
Cells(3 + y, 15).FormulaR1C1 = "=IF(COUNTIF(RC[-12],""*GRP*""),VLOOKUP(RC[-12],TBL_Tarifs!R5C3:R57C28,5,FALSE),"""")"
Cells(3 + y, 17).FormulaR1C1 = "=IF(COUNTIF(RC[-14],""*GRP*""),VLOOKUP(RC[-14],TBL_Tarifs!R5C3:R57C28,6,FALSE),"""")"
Cells(3 + y, 19).FormulaR1C1 = "=IF(COUNTIF(RC[-16],""*GRP*""),VLOOKUP(RC[-16],TBL_Tarifs!R5C3:R57C28,7,FALSE),"""")"
Cells(3 + y, 21).FormulaR1C1 = "=IF(COUNTIF(RC[-18],""*GRP*""),VLOOKUP(RC[-18],TBL_Tarifs!R5C3:R57C28,8,FALSE),"""")"
Cells(3 + y, 23).FormulaR1C1 = "=IF(COUNTIF(RC[-20],""*GRP*""),VLOOKUP(RC[-20],TBL_Tarifs!R5C3:R57C28,9,FALSE),"""")"
Cells(3 + y, 25).FormulaR1C1 = "=IF(COUNTIF(RC[-22],""*GRP*""),VLOOKUP(RC[-22],TBL_Tarifs!R5C3:R57C28,10,FALSE),"""")"
Cells(3 + y, 27).FormulaR1C1 = "=IF(COUNTIF(RC[-24],""*GRP*""),VLOOKUP(RC[-24],TBL_Tarifs!R5C3:R57C28,11,FALSE),"""")"
Cells(3 + y, 29).FormulaR1C1 = "=IF(COUNTIF(RC[-26],""*GRP*""),VLOOKUP(RC[-26],TBL_Tarifs!R5C3:R57C28,12,FALSE),"""")"
Cells(3 + y, 31).FormulaR1C1 = "=IF(COUNTIF(RC[-28],""*GRP*""),VLOOKUP(RC[-28],TBL_Tarifs!R5C3:R57C28,13,FALSE),"""")"
Cells(3 + y, 33).FormulaR1C1 = "=IF(COUNTIF(RC[-30],""*GRP*""),VLOOKUP(RC[-30],TBL_Tarifs!R5C3:R57C28,14,FALSE),"""")"
Cells(3 + y, 35).FormulaR1C1 = "=IF(COUNTIF(RC[-32],""*GRP*""),VLOOKUP(RC[-32],TBL_Tarifs!R5C3:R57C28,15,FALSE),"""")"
Cells(3 + y, 37).FormulaR1C1 = "=IF(COUNTIF(RC[-34],""*GRP*""),VLOOKUP(RC[-34],TBL_Tarifs!R5C3:R57C28,16,FALSE),"""")"
Cells(3 + y, 39).FormulaR1C1 = "=IF(COUNTIF(RC[-36],""*GRP*""),VLOOKUP(RC[-36],TBL_Tarifs!R5C3:R57C28,17,FALSE),"""")"
Cells(3 + y, 41).FormulaR1C1 = "=IF(COUNTIF(RC[-38],""*GRP*""),VLOOKUP(RC[-38],TBL_Tarifs!R5C3:R57C28,18,FALSE),"""")"
Cells(3 + y, 43).FormulaR1C1 = "=IF(COUNTIF(RC[-40],""*GRP*""),VLOOKUP(RC[-40],TBL_Tarifs!R5C3:R57C28,19,FALSE),"""")"
Cells(3 + y, 45).FormulaR1C1 = "=IF(COUNTIF(RC[-42],""*GRP*""),VLOOKUP(RC[-42],TBL_Tarifs!R5C3:R57C28,20,FALSE),"""")"
Cells(3 + y, 47).FormulaR1C1 = "=IF(COUNTIF(RC[-44],""*GRP*""),VLOOKUP(RC[-44],TBL_Tarifs!R5C3:R57C28,21,FALSE),"""")"
Cells(3 + y, 49).FormulaR1C1 = "=IF(COUNTIF(RC[-46],""*GRP*""),VLOOKUP(RC[-46],TBL_Tarifs!R5C3:R57C28,22,FALSE),"""")"
Cells(3 + y, 51).FormulaR1C1 = "=IF(COUNTIF(RC[-48],""*GRP*""),VLOOKUP(RC[-48],TBL_Tarifs!R5C3:R57C28,23,FALSE),"""")"
Cells(3 + y, 53).FormulaR1C1 = "=IF(COUNTIF(RC[-50],""*GRP*""),VLOOKUP(RC[-50],TBL_Tarifs!R5C3:R57C28,24,FALSE),"""")"
Cells(3 + y, 55).FormulaR1C1 = "=IF(COUNTIF(RC[-52],""*GRP*""),VLOOKUP(RC[-52],TBL_Tarifs!R5C3:R57C28,25,FALSE),"""")"
Cells(3 + y, 57).FormulaR1C1 = "=IF(COUNTIF(RC[-54],""*GRP*""),VLOOKUP(RC[-54],TBL_Tarifs!R5C3:R57C28,26,FALSE),"""")"
y = y + 1
End If
Next
'Mise en place de ligne Total Partie 1
Cells(y + 3, 1) = "Total Partie 1"
'Mise en forme total partie 1
Range(Cells(y + 3, 1), Cells(y + 3, 58)).Select
Call mise_en_forme_ligne_sous_totale
Cells(y + 3, 9).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 11).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 13).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 15).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 17).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 19).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 21).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 23).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 25).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 27).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 29).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 31).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 33).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 35).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 37).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 39).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 41).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 43).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 45).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 47).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 49).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 51).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 53).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 55).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])"
Cells(y + 3, 57).FormulaR1C1 = "=SUM(R[" & (-y) & "]C[0]:R[" & (-1) & "]C[0])" Je vous explique brièvement à quoi sert cette macro. J’ai plusieurs sites avec des inventaires différents. Pour chacun des sites j’ai créé un onglet dans lequel je vais sortir son inventaire (inventaire qui se trouve dans un seul et unique onglet où l’inventaire de chaque site y est renseigné). Pour chaque ligne de cet inventaire je vais chercher un tarif dans un 3e onglet suivant un prestataire (c’est là qu’est mon problème et que la simplification peut se faire).
En gros, dans ma macro j’ai déjà réussi à automatiser la création de ligne dépendant de l’inventaire, mais je ne me suis pas encore penché sur l’automatisation de la création de colonne correspondant d’abord au nom de site, désignation,… (pour les colonnes A à H) et chacun des prestataire pour les colonnes supérieures à H.
Auriez vous des solutions à me proposer ?
Je peux essayer de vous apporter un peu plus de précisions à mon problème si vous le souhaitez.
Merci d’avance pour vos réponses.
Bien cordialement.
Danette
Bonjour,
peu de chance que je sache t'aider mais si tu réfléchis un instant, il serait plus simple d'envoyer le fichier qui va avec -une copie anonymisée bien sur - et là ça peut aider !
Faut être balèze pour aider sans le fichier de base hein
P.
Merci pour ton retour si rapide.
Je peux t'envoyer mon fichier en MP si tu veux.
danette a écrit :Merci pour ton retour si rapide.
Je peux t'envoyer mon fichier en MP si tu veux.
Non, pas de MP mais je voulais te faire connaitre la manière de faire ici; il y aura surement un grand chef du VBA pour se pencher sur le bébé.
P.