Split Text file on the basis of specific no. of character

sanjuss2

Board Regular
Joined
Nov 28, 2014
Messages
65
Hi,
I have text file which must be like as under

0040025001200205000000018907082017
0040015001600405000000018907082017
0040015001600505000000018907082017
0040015001600205000000018907082017

I need to create multiple text files on the basis of 3 characters from 12 no. of character i.e. in bold

the file must contain same record i.e for 002.txt file

0040025001200205000000018907082017
0040015001600205000000018907082017

for 004.txt file
0040015001600405000000018907082017

for 005.txt file
0040015001600505000000018907082017

Is this possible with vba? if yes Thanks in advance.
Prompt helps will saved my time & efforts.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
this should do it.

Assuming you data starts in cell A1 and goes down.
Adjust your path as needed, don't forget the "" at the end

Rich (BB code):
Sub outputtotextfile()

fPath = "C:\Test\"

For r = 1 To Range("A65536").End(xlUp).Row
    fName = Mid(Cells(r, "A"), 12, 3)
    Open fPath & fName & ".txt" For Append As #1  'add to existing file
    Print #1 , Cells(r, "A")
    Close #1 
Next r
    
End Sub

hth

Ross
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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