Copying cells from multiple files in a folder

171z

New Member
Joined
Nov 15, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

Total VBA novice here. I would like to consolidate the data stored in multiple raw files which is stored in one folder. All the raw files have the same structure and sheet names.
The items I would like to consolidate are the name of the file, cell A3, A4 and A30 in Sheet 1 of the raw files.
The expected outcome should be something like this:
Filename Sheet1!A3Sheet1!A4Sheet1!A30
123.xlsxabc100101

Appreciate if anyone can help with this. Thanks!

p/s: Do let me know if this method is plausible using power query as well :)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Are the files CSVs or structured as Tables? If so, Power Query makes it very easy. You would set your source equal to a folder and expand content. The VBA solution is a bit more involved. I forget if cross-linking is forbidden here, but your google search would be something along the lines of "VBA loop through files in folder."
 
Upvote 0
Are the files CSVs or structured as Tables? If so, Power Query makes it very easy. You would set your source equal to a folder and expand content. The VBA solution is a bit more involved. I forget if cross-linking is forbidden here, but your google search would be something along the lines of "VBA loop through files in folder."

It is structured as table. The raw data is something like this:
Sheet1! A3abc
Sheet1! A4100
Sheet1! A30101

Appreciate if you can advise on how I can get the output below using power query.

Source.NameSheet1!A3Sheet1!A4Sheet1!A30
123.xlsxabc100101

Currently, I am stuck with this:
Power Query:
let
    Source = Folder.Files("C:\Desktop\Test\1. RAW"),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"ITEM", type text}, {"DETAILS", type any}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([ITEM] <> null))
in
    #"Filtered Rows"
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top