Exercice VBA - Trie de données
Salut tout le monde,
Je me permet de poster car je bloque sur un exercice VBA. Je suis plus tot à l'aise avec les formules Excel, mais le codage c'est pas trop ma sauce de base. Je vous liste l'exercice ci-dessous. J'ai deja commencer avec un bout de code pour ouvrir et transposer certaines donnés mais je n'arrive pas à allez plus loin. Aidez moi SVP
CONSIGNES :
•You are working in the Risk / Middle Office department of an Energy trading house•You receive the positions on oil reported by the team members in Europe, Asia and Americas in Excel files•You need to extract the positions, aggregate them and report them in a normalized format, so you
can have a view of the net position of the desk•ØRules:•Create a file name PositionAggregation.xlsm in which you are going to code the macro that•Extract the different positions of the team members, looping through all Excel files in the same folder•Aggregate it (i.e. if a trader is long 5 contracts X2022 and another short 10, the output is short 5)•Report it in a spreadsheet named “aggregated”•Traders are not always consistent: the name of the files can change. Please find a way to loop all files in
a folder. However the way a trader reports positions is not going to change.•Note that the delivery months need also to be normalized•The name of the spreadsheets with the position won’t evolve. It is name “pos”•If the spreadsheet is not found, please display a message saying the position has not been found for the
team XXX•Note that some positions are not reported by values, so you need to convert them•There are typos, you need to find a way to handle them (how would you do in the real life)
MON BOUT DE CODE
Sub ouvrirfichiers()
'Création des varaiables
Dim Fichier As String, Chemin As String
Dim Wb As Workbook
Chemin = "/Users/mohamedbadawy/Desktop/ProjetVBA /" 'Accès au dossier contenant les fichiers des positions
Fichier = Dir(Chemin & "*.xlsx") 'Configure la variable "Fichier" en precisant qu'elle correspond à tout les fichiers .xlsx du dossier "Chemin"
Do While Fichier <> "" 'Realise une boucle tant qu'il existe des fichier .xlsx
Set Wb = Workbooks.Open(Chemin & Fichier) 'Ouvre les fichiers .xlsx
'Selctionne toutes les feuilles des fichiers sources ouverts et les deplaces vers mon workboo(Avantage ca ferme les fichier sources directement sans les enregistrés)
Sheets.Select
Sheets.Move After:=Workbooks("PositionAggregation.xlsx").Sheets(1)
Fichier = Dir 'donne le chemin pour lesautres fichiers source
Loop
End Sub