+ Reply to Thread
Results 1 to 6 of 6

Ho to Create .TXT Subsets based on existing Excel data using VBA Macro

  1. #1
    Registered User
    Join Date
    02-25-2020
    Location
    india
    MS-Off Ver
    2016
    Posts
    6

    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.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼


    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 FilterF%, S$, Rg As Range
        
    For Each Ft In Me.AutoFilter.Filters
              
    If Ft.On Then F 1Ft.Criteria1
        Next
            
    If <> 2 Then Beep: Exit Sub
            S 
    "TXT_" Replace$(Replace$(Replace$(S"="""), "%"""), Format(0"."), "") & "_mmdd .txt"
            
    FreeFile
            Open ThisWorkbook
    .Path Application.PathSeparator 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 » !

  3. #3
    Registered User
    Join Date
    02-25-2020
    Location
    india
    MS-Off Ver
    2016
    Posts
    6

    Re: Hi ! Try this ‼

    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.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Your bad ‼ Please read & apply at least the dark red direction !

    As a starter, you may have to amend it … (next time well elaborate your need in the initial post)
    As I'm now off-web for half a day, maybe more …

  5. #5
    Registered User
    Join Date
    02-25-2020
    Location
    india
    MS-Off Ver
    2016
    Posts
    6

    Re: Ho to Create .TXT Subsets based on existing Excel data using VBA Macro

    Sorry!,
    I tried to run after pasting in Sheet1 worksheet module, but it is not running.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    See in VBE step-by-step mode - hitting F8 key - what's wrong on your side as it well works on mine …

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to create a Database from existing Data
    By rehana402003 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-05-2017, 09:53 PM
  2. Replies: 11
    Last Post: 11-04-2013, 04:32 PM
  3. Replies: 3
    Last Post: 10-14-2013, 03:06 PM
  4. Macro to concatenate cell contents from subsets of data
    By Rjhopkins1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-15-2013, 01:34 PM
  5. [SOLVED] Create A summary based on Existing Data
    By jebindavidson in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 04-25-2013, 12:11 AM
  6. [SOLVED] How do I create an excel macro to append to a cell with existing i
    By zola_tiara in forum Excel General
    Replies: 4
    Last Post: 09-14-2005, 04:05 PM
  7. [SOLVED] Dynamically create worksheets in Excel based off existing data?
    By tlozier in forum Excel General
    Replies: 1
    Last Post: 09-09-2005, 08:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1