Forum Discussion
power querry
I don't recognize your problem and the last thing I would do is choose VBA over PQ. Would you mind sharing the link to a file (on OneDrive or similar) that demonstrates the issue?
Or else, the code of the query that 'sometimes' generates the blank column.
- LéaJun 19, 2026Copper Contributor
Thank you for the answer.
I use Power Query only to retrieve data from workbooks in a folder on the users' computers. They enter the file path in a cell.
That's the reason why I was thinking of changing for only VBA. this is the code in PQ (M language)
let// Charger la table nommée "nom_utilisateur" depuis le classeur Excel courant
UserPathTable = Excel.CurrentWorkbook(){[Name="nom_utilisateur"]}[Content],
// Extraire le chemin du dossier depuis la première ligne
FolderPath = UserPathTable{0}[nom_utilisateur_colonne],
// Construire le chemin complet du fichier Excel
FullFilePath = FolderPath & "\filename.xlsx",
// Charger le fichier Excel
Source = Excel.Workbook(File.Contents(FullFilePath), null, true),
// Extraire les données de la feuille "sheetname" et les mettre en mémoire pour éviter le verrouillage du fichier gràce à la fonction table.buffer
BufferedSheet = Table.Buffer(Source{[Item="sheetname", Kind="Sheet"]}[Data]),
// Travailler à partir de la table mise en mémoire
Sheet_Data = BufferedSheet,
// Extraire la première ligne
FirstRow = Sheet_Data{0},
// Vérifier si la première ligne est complètement vide (null ou vide "")
IsFirstRowEmpty = List.AllTrue(List.Transform(Record.ToList(FirstRow), each _ = null or _ = "")),
// Supprimer la première ligne seulement si elle est vide
CleanedData = if IsFirstRowEmpty then Table.Skip(Sheet_Data, 1) else Sheet_Data,
// Promouvoir la première ligne restante comme en-têtes
PromotedHeaders = Table.PromoteHeaders(CleanedData, [PromoteAllScalars = true]),
// Récupérer la liste des noms de colonnes
ColumnNames = Table.ColumnNames(PromotedHeaders),
// Créer une liste dynamique avec le type "any"
DynamicColumnTypes = List.Transform(ColumnNames, each {_, type any}),
// Appliquer les types dynamiques
FinalTable = Table.TransformColumnTypes(PromotedHeaders, DynamicColumnTypes)
in
FinalTable