Bonjour à tous,
j'ai écrit un code vba qui fonctionne mais.... il est vraiment moche et je pense qu'il doit exister une version bien plus rapide et performante en temps (et mémoire) car je dois appliquer celui-ci sur un fichier de 30,000 lignes.
J'ai joint un fichier pour expliquer. Dans les lignes de la colonne B j'ai des marques et modèles de voitures et dans les colonnes C à H les types de moteurs disponibles pour chacun d'eux. Je souhaiterai que la valeur de cellule I11 et celles au-dessous, il y ait une concaténation des en-tête de colonnes pour les moteurs disponibles (c'est à dire les cellules > 0).
Comment modifier le code en ajoutant une boucle de la ligne 11 à la dernière ligne non vide ?
Et est-ce que vous auriez une idée pour que le code prenne en compte toutes les combinaisons possibles ? Par exemple, une offre essence avec tous les autres, puis seulement 1 autre, 2 autres, etc. puis sans essence, etc. J'avoue que dans mon code, certaines ont dû être oubliées.
Je vous remercie. Ci-bas mon code actuel :-(
Michel
Sub Macro1()
Dim FinChecks As Long
Dim Propulsions As String
Sheets("CS4 & Propulsions").Select
ActiveWorkbook.Worksheets("CS4 & Propulsions").Sort.SortFields.Clear 'Supprime les tris automatiques potentiels
FinChecks = Range("B" & Rows.Count).End(xlUp).Row
Range("I11").Select
Propulsions = Range("I11").Text
'Gasoline
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:H11")) = 0 Then Range("I11").Value = "100% Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And WorksheetFunction.Sum(Range("F11:H11")) = 0 Then Range("I11").Value = "Gas / CNG/LPG"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:E11")) = 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Gas / Hybrid Diesel"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:E11")) = 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / CNG/LPG / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas / Hybrid Diesel"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Hybrid Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And WorksheetFunction.Sum(Range("E11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / CNG/LPG / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / CNG/LPG / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / CNG/LPG / Hybrid Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Diesel / Electric"
'Diesel
If Range("C11").Value = 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:H11")) = 0 Then Range("I11").Value = "100% Diesel"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And WorksheetFunction.Sum(Range("F11:H11")) = 0 Then Range("I11").Value = "Diesel / CNG/LPG"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Diesel / Hybrid Gas"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Diesel / Hybrid Diesel"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Diesel / Hybrid Gas / Hybrid Diesel"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("E11:G11")) = 0 And Range("H11").Value = 0 Then Range("I11").Value = "Diesel / Electric"
'Hybrid Gas
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "100% Hybrid Gas"
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Hybrid Gas / Hybrid Diesel"
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Hybrid Gas / Hybrid Diesel / Electric"
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Hybrid Gas / Electric"
'Hybrid Diesel
If WorksheetFunction.Sum(Range("C11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "100% Hybrid Diesel"
If WorksheetFunction.Sum(Range("C11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Hybrid Diesel / Electric"
'Electric
If WorksheetFunction.Sum(Range("C11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "100% Electric"
End Sub
j'ai écrit un code vba qui fonctionne mais.... il est vraiment moche et je pense qu'il doit exister une version bien plus rapide et performante en temps (et mémoire) car je dois appliquer celui-ci sur un fichier de 30,000 lignes.
J'ai joint un fichier pour expliquer. Dans les lignes de la colonne B j'ai des marques et modèles de voitures et dans les colonnes C à H les types de moteurs disponibles pour chacun d'eux. Je souhaiterai que la valeur de cellule I11 et celles au-dessous, il y ait une concaténation des en-tête de colonnes pour les moteurs disponibles (c'est à dire les cellules > 0).
Comment modifier le code en ajoutant une boucle de la ligne 11 à la dernière ligne non vide ?
Et est-ce que vous auriez une idée pour que le code prenne en compte toutes les combinaisons possibles ? Par exemple, une offre essence avec tous les autres, puis seulement 1 autre, 2 autres, etc. puis sans essence, etc. J'avoue que dans mon code, certaines ont dû être oubliées.
Je vous remercie. Ci-bas mon code actuel :-(
Michel
Sub Macro1()
Dim FinChecks As Long
Dim Propulsions As String
Sheets("CS4 & Propulsions").Select
ActiveWorkbook.Worksheets("CS4 & Propulsions").Sort.SortFields.Clear 'Supprime les tris automatiques potentiels
FinChecks = Range("B" & Rows.Count).End(xlUp).Row
Range("I11").Select
Propulsions = Range("I11").Text
'Gasoline
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:H11")) = 0 Then Range("I11").Value = "100% Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And WorksheetFunction.Sum(Range("F11:H11")) = 0 Then Range("I11").Value = "Gas / CNG/LPG"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:E11")) = 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Gas / Hybrid Diesel"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:E11")) = 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / CNG/LPG / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Diesel"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas / Hybrid Diesel"
If Range("C11").Value > 0 And WorksheetFunction.Sum(Range("D11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Hybrid Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And WorksheetFunction.Sum(Range("E11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / CNG/LPG / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / CNG/LPG / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value = 0 And Range("E11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / CNG/LPG / Hybrid Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / Hybrid Diesel / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Gas / Electric"
If Range("C11").Value > 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Gas / Diesel / CNG/LPG / Hybrid Diesel / Electric"
'Diesel
If Range("C11").Value = 0 And Range("D11").Value > 0 And WorksheetFunction.Sum(Range("E11:H11")) = 0 Then Range("I11").Value = "100% Diesel"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("E11").Value > 0 And WorksheetFunction.Sum(Range("F11:H11")) = 0 Then Range("I11").Value = "Diesel / CNG/LPG"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "Diesel / Hybrid Gas"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Diesel / Hybrid Diesel"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Diesel / Hybrid Gas / Hybrid Diesel"
If Range("C11").Value = 0 And Range("D11").Value > 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("E11:G11")) = 0 And Range("H11").Value = 0 Then Range("I11").Value = "Diesel / Electric"
'Hybrid Gas
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And WorksheetFunction.Sum(Range("G11:H11")) = 0 Then Range("I11").Value = "100% Hybrid Gas"
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "Hybrid Gas / Hybrid Diesel"
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Hybrid Gas / Hybrid Diesel / Electric"
If WorksheetFunction.Sum(Range("C11:E11")) = 0 And Range("F11").Value > 0 And Range("G11").Value = 0 And Range("H11").Value > 0 Then Range("I11").Value = "Hybrid Gas / Electric"
'Hybrid Diesel
If WorksheetFunction.Sum(Range("C11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value = 0 Then Range("I11").Value = "100% Hybrid Diesel"
If WorksheetFunction.Sum(Range("C11:F11")) = 0 And Range("G11").Value > 0 And Range("H11").Value > 0 Then Range("I11").Value = "Hybrid Diesel / Electric"
'Electric
If WorksheetFunction.Sum(Range("C11:G11")) = 0 And Range("H11").Value > 0 Then Range("I11").Value = "100% Electric"
End Sub