Export to text files by macro

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
I have large data in Column A and I want export every 500 of these data to a text file ....
Can you help me about that?
A1:A500 should be exported to text file called Yasser1
and A501:1000 should be exported to text file called Yasser2
and so on
the range is very large
A1:A650000
 
I'm not 100% sure of the format you need these files in, or to what you will use them for afterwards. But, just in case what you are after is just essentially a text log of the data items try this on for size:

Code:
Sub exportData()
    
    Dim i As Integer, i2 As Integer
    Dim myFile As String
    
    i = 1
    i2 = 1
    
    For Each c In Range("A1:A2001") '<<< Change this to suit your needs
        If i2 = 501 Then
            i = i + 1
            i2 = 1
        End If
        myFile = "Yasser" & i
        addToText c.text, myFile
        i2 = i2 + 1
    Next
    
End Sub

Sub addToText(ByVal text As String, myFile As String)
On Error Resume Next

    Dim myPath As String
    Dim fnum As Variant
    
    myPath = "C:\" '<<< Change this to suit your needs
    myFile = myPath & myFile
    fnum = FreeFile()
    
    Open myFile For Append As fnum
    Print #fnum, text
    Close #fnum
    
End Sub
I didn't notice your reply
thanks
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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