Import lots of txt files into separate rows in one worksheet

MP_7

New Member
Joined
Feb 23, 2020
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm not good at VBA and neither at power gueries, but I'm trying with the latter, and I'm having some troubles.
What I have is a lot of txt files and the data in those files is just row after row, part of it below
2
3
144
2.50
73
2.50
OR4_GL02_300_3K_2A
etc...

I just need what each row contains into separate columns all in one row

for example:
file 1
A
B
C

file 2
D
E
F

Result:
ABC
DEF

I defined in the query to import only the first 40 rows but after I load it literally imports those 40 values into one row. I don't know how to import the rest of the files?

Thx.
 
Unofrtunately no :)
There has to be only one row for each file, in your example there are multiple rows for one file
Let me just make an example of what the first 2 rows should look like

Book1.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAF
1Custom.1Custom.2Custom.3Custom.4Custom.5Custom.6Custom.7Custom.8Custom.9Custom.10Custom.11Custom.12Custom.13Custom.14Custom.15Custom.16Custom.17Custom.18Custom.19Custom.20Custom.21Custom.22Custom.23Custom.24Custom.25Custom.26Custom.27Custom.28Custom.29Custom.30Custom.31Custom.32
2GMR Enlights231442.50732.50OR4_GL02_300_3K_2AOR4_GL02_300_3K_2AOR4_GL02_300_3K_2AOR4_GL02_300_3K_2A.LDT05-09-2019 / Agilux40020060150150111199.81100.001.000.0011OR4_GL02_300_3K_2A1030.183000709.75
3GMR Enlights231442.50732.50OR4_GL02_350_3K_2AOR4_GL02_350_3K_2AOR4_GL02_350_3K_2AOR4_GL02_350_3K_2A.LDT05-09-2019 / Agilux40020060150150111199.81100.001.000.0011OR4_GL02_350_3K_2A1197.6230007011.46
Sheet1
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
GMR Enlights is the first value in every txt file.
No probs bud, I appreciate every second you can spare, thank you very much!
 
Upvote 0
I know it's the first label but is there more labels?
here is just for this single label
CustomList.1List.2List.3List.4List.5List.6List.7List.8List.9List.10List.11List.12List.13List.14List.15List.16List.17List.18List.19List.20List.21List.22List.23List.24List.25List.26List.27List.28List.29List.30List.31List.32
GMR Enlights231442.50732.50OR4_GL02_300_3K_2AOR4_GL02_300_3K_2AOR4_GL02_300_3K_2AOR4_GL02_300_3K_2A.LDT05-09-2019 / Agilux40020060150150111199.81100.001.000.0011OR4_GL02_300_3K_2A1030.183000709.750.21576
GMR Enlights231442.50732.50OR4_GL02_350_3K_2AOR4_GL02_350_3K_2AOR4_GL02_350_3K_2AOR4_GL02_350_3K_2A.LDT05-09-2019 / Agilux40020060150150111199.81100.001.000.0011OR4_GL02_350_3K_2A1197.6230007011.460.21576
GMR Enlights231442.50732.50OR4_GL02_400_3K_2AOR4_GL02_400_3K_2AOR4_GL02_400_3K_2AOR4_GL02_400_3K_2A.LDT05-09-2019 / Agilux40020060150150111199.81100.001.000.0011OR4_GL02_400_3K_2A1362.1830007012.610.21576
GMR Enlights231442.50732.50OR4_GL02_450_3K_2AOR4_GL02_450_3K_2AOR4_GL02_450_3K_2AOR4_GL02_450_3K_2A.LDT05-09-2019 / Agilux40020060150150111199.81100.001.000.0011OR4_GL02_450_3K_2A1523.9530007013.330.21576

most of the values in the columns are the same but sometimes they differ
and as you said number of columns are limited to 32
 
Upvote 0
If I understand what you're asking, no it's the only label I mean it's 1 per file
Holy crap, I think you got it, how the hell did you do that? :biggrin:
 
Upvote 0
refresh thread and see if this is what you want because total number of columns is 5587
 
Upvote 0
Yes I know that's the problem, everything after the 32nd value is not needed, that's why we talked about 32 columns
 
Upvote 0
Not sure what you mean with M, any way you want as long as it lets me understand how you did it :)
 
Upvote 0
M is the name of Power Query language
so I'll give you M
change source path to your folder with txt files
Power Query:
let
    Source = Folder.Files("D:\test\mp_7\txt"),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from txt", each #"Transform File from txt"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from txt"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from txt", Table.ColumnNames(#"Transform File from txt"(#"Sample File"))),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded Table Column1", "Custom", each if Text.Contains([Column1], "GMR Enlights") then [Column1] else null),
    #"Grouped Rows" = Table.Group(#"Added Conditional Column", {"Source.Name", "Custom"}, {{"Count", each _, type table}, {"CR", each Table.RowCount(_), type number}}),
    #"Filled Down" = Table.FillDown(#"Grouped Rows",{"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([CR] = 5587)),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "List", each [Count][Column1]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"List", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "List", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"List.1", "List.2", "List.3", "List.4", "List.5", "List.6", "List.7", "List.8", "List.9", "List.10", "List.11", "List.12", "List.13", "List.14", "List.15", "List.16", "List.17", "List.18", "List.19", "List.20", "List.21", "List.22", "List.23", "List.24", "List.25", "List.26", "List.27", "List.28", "List.29", "List.30", "List.31", "List.32"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Source.Name", "CR"})
in
    #"Removed Columns"
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

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