CSV files are funny animals.If I open/read the file as a text stream, and try 
to parse each line using a comma (,) delimiter,I get a different result than if 
I were to open the .csv file in excel.
Consequently, what I've done in the past is read the file and write the line to 
another .csv file without modifying the line. 
Try implementing this code:
Option Explicit
Public Const ForReading = 1, ForWriting = 2, ForAppending = 8Sub Split_File()
    Dim fso, fr, fw, Str
    Dim lCnt As Long, lMax As Long
    Dim fPath, File_Input, File_Out, File_Output
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    fPath = "C:\temp\VBA\Mahesh\"
    File_Input = "Test_Input.csv"
    File_Out = "Output_" ' Output file name prefix
    '-------------------------------------------------------------
    lMax = 100000 ' Maximum number of lines per file
    '-------------------------------------------------------------
    ' Open Input file
    '-------------------------------------------------------------
    Set fr = fso.OpenTextFile(fPath & File_Input, ForReading)
    If (Err.Number <> 0) Then
        MsgBox "Could not open " & Chr(13) & fPath & File_Input
        Exit Sub
    End If
    '-------------------------------------------------------------
    lCnt = 0
    ' Open first output file
    File_Output = Format(Int(lCnt / lMax), File_Out & "000.csv")
    Set fw = fso.OpenTextFile(fPath & File_Output, ForWriting, True)
    Do While Not fr.atendofstream
        lCnt = lCnt + 1
        Str = fr.readline
        fw.WriteLine Str
        '----------------------------------------------------
        ' If Line count equals maximum line count,
        ' Close Output file and open next file
        '----------------------------------------------------
        If (lCnt Mod lMax = 0) Then
            fw.Close
            File_Output = Format(Int(lCnt / lMax), File_Out & "000.csv")
            Set fw = fso.OpenTextFile(fPath & File_Output, ForWriting, True)
        End If
    Loop
    '-------------------------------------------------------------
    ' Close files
    '-------------------------------------------------------------
    fw.Close
    fr.Close
    MsgBox "finished"
End SubPaul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
----------------------------------------- 

    On Wednesday, April 20, 2016 12:43 AM, Mahesh <mahender.bi...@gmail.com> 
wrote:
 
 

 yes, it is .csv
On Tue, Apr 19, 2016 at 10:18 PM, Devendra Sahay 
<devendrasahanypt...@gmail.com> wrote:

Hi Mahesh,

Please confirm the file format, is it .csv




On Tue, Apr 19, 2016 at 10:16 PM, Mahesh <mahender.bi...@gmail.com> wrote:

Hi,I want to split it by rows.For example- 
if the text file contains 12 lacs rows, then I would like make 03 different 
text files with 4lacs row in each one of them.On Apr 19, 2016 5:48 PM, "Paul 
Schreiner" <schreiner_p...@att.net> wrote:

What criteria do you want to divide between the files?How do you want to split 
it into columns? 
It is fairly easy to write a VBA macro that will open the text file and read it 
line-by-line.then, depending on your criteria, write the line to an Excel 
workbook or simply separate sheets in a single workbook (which can then be 
moved to separate workbooks)
Can you share a sample (large) of the data?
Paul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
----------------------------------------- 

    On Monday, April 18, 2016 11:29 PM, Mahesh <mahender.bi...@gmail.com> wrote:
 
 

 Hi Team,
I have a huge text file containing around 10 Lacs or more rows, I want to split 
it into 2 or more excel files.
I tried the few software but nothing happens.
Hope for a better solution from experts....
Rgds,Mahender Bisht-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


 
   -- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.




-- 

With Regard !!!Devendra Rahi
-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
 
NOTE : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.


 
  

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to