• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Code to convert data to different files

zamankk

New Member
Please can you help me with a code to convert the data in sheet 1 to different txt files. I would like to convert 3 rows into different files.
 
I don't require the header to each file. New file to be created after every 3 rows.

thanks
 

Attachments

  • Book1.xlsx
    8 KB · Views: 3
Despite the complete technical explanation any forum expects in the initial post​
maybe with the expected text files attachment according to the source data workbook …​
 
Hi Marc - I am attaching the source file and the expected .txt files
 

Attachments

  • FileC.txt
    73 bytes · Views: 1
  • FileB.txt
    73 bytes · Views: 1
  • FileA.txt
    68 bytes · Views: 1
  • Book1.xlsx
    7.9 KB · Views: 3
As a beginner starter demonstration (edit v2) :​
Code:
Sub Demo1()
  Const E = " .csv"
    Dim F%, P$, Rw As Range, N%
        F = FreeFile
        P = ThisWorkbook.Path & Application.PathSeparator & "XL export "
    For Each Rw In Sheet1.UsedRange.Rows
        If Rw.Row Mod 3 = 1 Then Close #F: N = N + 1: Open P & N & E For Output As #F Else Print #F,
        Print #F, Join(Application.Index(Rw.Value2, 1, 0), ",");
    Next
        Close #F
End Sub
Do you like it ? So thanks to click on bottom right Like !​
 
Hello Marc, is it possible to define a range in macro for the columns.
For example I would like to convert only the data from column A to H in sheet 1, which is linked by formula to another sheet. In the next column I have created a macro button using the code you provided for creating the separate files.
Also the sheet 1 has got formula for taking the data from the other sheet. so when I request for splitting the data in new sheet, the cells which have formula is also getting converted though the text files have blank info.
Plz help. Thanks
 

Attachments

  • Upload_test.xlsx
    18.5 KB · Views: 2
Why a xlsx file so w/o any code ?​
Why the initial attachment does not have any formula ?!​
Proceeding like this means you are enough confident with your Excel / VBA skills to amend any code …​
According to your last attachment the demonstration revamped :​
Code:
Sub Demo1r()
  Const E = " .csv"
    Dim F%, P$, R&, N%
        F = FreeFile
        P = ThisWorkbook.Path & Application.PathSeparator & "XL export "
    With Sheet1.UsedRange
        For R = 1 To .Columns(1).Find("*", , xlValues, , , xlPrevious).Row
            If R Mod 3 = 1 Then Close #F: N = N + 1: Open P & N & E For Output As #F Else Print #F,
            Print #F, Join(Application.Index(.Rows(R).Value2, 0), ",");
        Next
    End With
        Close #F
End Sub
You may Like it !
 
Thanks Marc. I wanted to upload the macro enabled file but the chat didn’t give me the option to upload it. I will try this code in the sheet and update you.
Thanks.
 
Back
Top