Ho to Create .TXT Subsets based on existing Excel data using VBA Macro
Hello Guys,
I need to create Subsets for the data which I have, which is dynamic, using Excel VBA.
I have data in the form of table, whose column headings are Code, %, & Transaction ID as in the table 1 (Attached).
I need to create subsets in .txt file which only shows Transaction ID's in it based on the combinations between Code and %.
For example, if I filter Code 1001, I see 42.10% & 55.10%. For the first combination of code 1001 & 42.10%, the transaction ID’s only should be copied to a .txt file and this .txt file should be saved with the naming convection using “TXT_Code%_ddmm” format.
Example of the combinations:
Example 1:
In the Table 2 (Attached), i have filtered 1001 Code and 42.10%. I need transaction Id’s only should be copied to a new .txt file, and its naming convection should be as “TXT_1001421_ddmm” format and save this .Txt file in the folder.
Example 2:
In the table 3 (attached), i have filtered 1001 Code and 55.10%. I need transaction Id’s only should be copied to a new .txt file, and its naming convection should be as “TXT_1001551_ddmm” format and save this file in the folder.
The data is always dynamic, and the combinations are also dynamic.
I have attached the sample data and the sample .txt file.
Request your kind help in this matter, as this will save lo of time for the huge data I have.
Thank you for your help in Advance.
Just amend this beginner starter - paste it to the Sheet1 worksheet module - for all you forgot to well explain :
PHP Code:
Sub Demo1() Dim Ft As Filter, F%, S$, Rg As Range For Each Ft In Me.AutoFilter.Filters If Ft.On Then F = F + 1: S = S & Ft.Criteria1 Next If F <> 2 Then Beep: Exit Sub S = "TXT_" & Replace$(Replace$(Replace$(S, "=", ""), "%", ""), Format(0, "."), "") & "_mmdd .txt" F = FreeFile Open ThisWorkbook.Path & Application.PathSeparator & S For Output As #F For Each Rg In [_FilterDatabase].Columns(3).Rows("2:" & [_FilterDatabase].Rows.Count) If Not Rg.Hidden Then Print #1, Rg.Value2 Next Close #F End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon « ★ Add Reputation » !
Hi Marc,
yes i know i am have not explained my query well Sorry about that.
But thank u for trying to help me.
When I try to run the macro, i am seeing the error. - "Invalid use of Me Keyword ".
Please help.
Bookmarks