Object dictionnary
Bonjour à toutes et tous,
j'ai une question concernant la méthode à suivre pour générer un tableau récap de donnée
jusqu'ici je récupérais des champs uniques via un dictionnaire
Set dic_statuts = CreateObject("Scripting.Dictionary")
Set tb_projects = [Projects].ListObject
With tb_projects
For i = 0 To .ListRows.Count
Acronym = .ListColumns("Acronym").DataBodyRange.Rows(i)puis par exemple un peu plus loin sur un autre onglet
With Worksheets("Budget")
On Error Resume Next
Project_Range = Application.Match(id_projet, .Range("A:A"), 0)
Budget_Requested = Empty
If Err = 0 Then
Budget_Requested = .Range("A:O")(Project_Range, 15)
End Ifmais voila que désormais j'ai besoin de récupérer plusieurs lignes d'un même onglet
en effet dans l'onglet reporting j'ai pour chaque id_projet plusieurs périodes (au pire 6) sur plusieurs lignes
donc si j'applique la même technique ça ne me sortira que la première ligne, normal me direz vous
With Worksheets("Reporting")
On Error Resume Next
Project_Range = Application.Match(id_projet, .Range("A:A"), 0)
Id_Period = Empty
If Err = 0 Then
Id_Period = .Range("A:O")(Project_Range, 2)
Start_Period = .Range("A:O")(Project_Range, 5)
End_Period = .Range("A:O")(Project_Range, 7)
End If
End Withma question est donc de savoir comment je peux procéder
je pensais à un truc du style
nb_periods = Application.WorksheetFunction.CountIf(Worksheets("Reporting").Range("A:A"), id_projet)
For i = 0 To nb_accounts
Id_Period = .Range("A:O")(Project_Range, 2)
Next imais
1) je ne sais pas si c'est la meilleure méthode
2) je ne sais pas comment indiquer par exemple Id_Period & i
je m'en remet donc à vos avis
merci par avance
bonne journée
Bonjour,
quel est le lien du sujet avec le titre ? j'avais supposé au départ qu'il s'agissait de scripting.dictionary (avec un seul n), mais c'est peut-être tout simplement un dictionnaire que tu veux créer ...
pour résoudre, c'est quand même complexe sans disposer d'un fichier ... si tu pouvais en faire un simplifié et ciblé sur la demande !
Bonjour,
desolé si mon titre vous à induit en erreur, je le pensais approprié car concernait le dictionnaire mais vous avez raison.
disons que le code à optimiser serait celui-ci
nb_periods = Application.WorksheetFunction.CountIf(Worksheets("Reporting").Range("A:A"), id_projet) - 1
If (nb_periods >= 1) Then
Start_Period_1 = .Range("A:O")(Project_Range, 5)
End_Period_1 = .Range("A:O")(Project_Range, 7)
End If
If (nb_periods >= 2) Then
Start_Period_2 = .Range("A:O")(Project_Range + 1, 5)
End_Period_2 = .Range("A:O")(Project_Range + 1, 7)
End If
If (nb_periods >= 3) Then
Start_Period_3 = .Range("A:O")(Project_Range + 2, 5)
End_Period_3 = .Range("A:O")(Project_Range + 2, 7)
End If
If (nb_periods >= 4) Then
Start_Period_4 = .Range("A:O")(Project_Range + 3, 5)
End_Period_4 = .Range("A:O")(Project_Range + 3, 7)
End If
If (nb_periods >= 5) Then
Start_Period_5 = .Range("A:O")(Project_Range + 4, 5)
End_Period_5 = .Range("A:O")(Project_Range + 4, 7)
End If
If (nb_periods >= 6) Then
Start_Period_6 = .Range("A:O")(Project_Range + 5, 5)
End_Period_6 = .Range("A:O")(Project_Range + 5, 7)
End Ifsachant qu'a la fin j'affiche via
dic_projects(id_projet) = Array(statut, Acronym, Topic, début, fin, commentaire, Investigator_firstname, Investigator_name, CLng(Budget_Requested), Start_Period_1, End_Period_1, Start_Period_2, End_Period_2, Start_Period_3, End_Period_3, Start_Period_4, End_Period_4, Start_Period_5, End_Period_5, Start_Period_6, End_Period_6)difficile de mettre en place un fichier anonymisé au à la vue du nombre d'onglet ..
merci à vous si possible toutefois