Forum

SCRIPT TO COPY MULT...
 
Notifications
Clear all

SCRIPT TO COPY MULTIPLE TEXT FILES ROWS AND PASTE OUTPUT IN COLUMNS ON EXCEL FOR EACH FILE

4 Posts
2 Users
0 Reactions
95 Views
(@mr-motha)
Posts: 7
Active Member
Topic starter
 

Hi Team,

I need a VBA script that can copy multiple text file rows and paste in excel columns.

See attached example of file contents and expected excel file output.

Rgds.

 
Posted : 08/06/2021 4:54 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Themba,
It's easier with Power Query,

see file attached: just put all text files in a folder, change the path to that folder in the excel output file and press Refresh All button from Data tab.

The only problem I see is that you have a header file mixed between data files, not obvious which file has the headers.

 
Posted : 10/06/2021 1:12 pm
(@mr-motha)
Posts: 7
Active Member
Topic starter
 

Thanks Catalin,

This will greatly assist.

The files do not necessarily have a header file as they all contain data.

Is there a way of increase the number of columns to be pulled as the files I'm working with have various number of rows.

Rgds.

 
Posted : 11/06/2021 10:14 am
(@catalinb)
Posts: 1937
Member Admin
 

All you have to do is to replace in the query:
= Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column1", "Column2", "Column3", "Column4"}, {"Column1", "Column2", "Column3", "Column4"})

with:
= Table.ExpandTableColumn(#"Removed Columns", "Custom", Table.ColumnNames(Table.Combine(#"Removed Columns"[Custom])), Table.ColumnNames(Table.Combine(#"Removed Columns"[Custom])))

 
Posted : 11/06/2021 10:46 am
Share: