Help with data import : from txt file to excel

Npsays

Board Regular
Joined
Dec 17, 2004
Messages
70
I have a text file which has data(sample data below), i
cannot import data directly into the excel sheet because
its a large file and it limits the excel rows for import.
I need to import from the text file phase by phase, the
data required.
Presume I have in the first line 'asmt 00005', i need to get
all the data until again i hit the other line 'asmt00006' and this data has to be parsed on fixedwidth . I need to know how do I improvise my macro to ensure that it starts import only from the first occurance of 'asmt 00005' untill it reaches 'asmt00006'
Since I am not too good with macros , I am importing the file from a specified row ( which can be different each time) . Please also note that I need theimported data as fixed width .
My macro's excerpt:-


Sub Macro1()
A1 = "INPUT THE DATE TO BE EXTRACTED"
A2 = "DATE FORMAT DDMMYY"
A = InputBox(A1 + " " + A2, "MIS EXTRACTOR")

D = Mid(A, 1, 2)
M = Mid(A, 3, 2)
Y = Mid(A, 5, 2)
TX = "as"
P = "J:\prod\asmtrpts\"
DT = P + TX + Y + M + D
DT1 = TX + Y + M + D
ChDir "J:\prod\asmtrpts\"
Workbooks.OpenText DT, xlWindows, 24000, xlFixedWidth, FieldInfo:=Array(Array(0, 1))

Txt. File Used for extracting data:-
JAS000000 - S140 wyx pno - IA (PRODUCTION)
JASM ORG 001 REPRESENTATIVE ACTION TOTALS PAGE 4
 TIME 17:22:39
DACTI 0 .00 0 .00 9 .00
 DADDR 3 .00 4 .00 80 .00
 DBTI 1 .00 1 .00 56 .00
ASMT00005 - S140 wyx pno - IA (PRODUCTION)
JASM ORG 001 REPRESENTATIVE ACTION TOTALS PAGE 4
 TIME 17:22:39
DACTI 0 .00 0 .00 9 .00
 DADDR 3 .00 4 .00 80 .00
JAS000000 - S140 wyx pno - IA (PRODUCTION)
JASM ORG 001 REPRESENTATIVE ACTION TOTALS PAGE 4
ASMT00006 - S140 wyx pno - IA (PRODUCTION)


pLS help
Thanks !!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
My recommendation would be to import your txt into an Access database, then if you need to work with it in Excel, create a query in Access to filter your data to a size Excel can handle. Trying to import, "phase by phase" would be an import nightmare.
 
Upvote 0
Thanks Datsmart !
I had thought of that option too, but unfortunately it may not be possible for me to use access. Could there be a way , wherein the excel reads the txt file before importing and searches for first occurance of "asmt" . prompts back with line number and the same could be replaced with row number ( "24000") as mentioned below ?

Workbooks.OpenText DT, xlWindows, 24000, xlFixedWidth, FieldInfo:=Array(Array(0, 1))

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,214
Members
448,874
Latest member
b1step2far

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