+ Reply to Thread
Results 1 to 7 of 7

Macro to Create Individual Records from List with Qtys

  1. #1
    Registered User
    Join Date
    05-18-2009
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Macro to Create Individual Records from List with Qtys

    I receive data from a customer such as in file "Applied Data.xls"
    Column A is Quantity. Column B is data.

    I need to run this data through software that only accepts individual records. For example Qty 15 of Data 9929 in first line of file must show "9929" listed 15 times to print correctly.

    2nd attachment shows the resulting .csv file that I need with example data & quantities. Cells A1, "Applied1" and A2 "txtField1" must remain UNCHANGED and always be present.
    Can a macro be written to take data from "Applied Data.xls" and create a new file looking like "Applied1.csv"

    It must work with any number of records. For example, there may be dozens of data records with multiple Qtys required of each.
    If not a macro, then what? Open to suggestions
    Attached Files Attached Files

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Macro to Create Individual Records from List with Qtys

    Administrative note
    Please update your profile as necessary to properly reflect the exact version(s) of Excel your question relates to ( if you are not using XL2003 any more). Thanks

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

    Cool Hi ! Try this ‼


    An Excel 2003 beginner VBA starter demonstration (in fact works whatever the version !) :

    PHP Code: 
    Sub Demo1()
        
    Dim VF%, R&
            
    ActiveSheet.UsedRange.Columns("A:B").Value2
            F 
    FreeFile
            Open ActiveWorkbook
    .Path Application.PathSeparator "Applied1 .csv" For Output As #F
            
    Print #F, "Applied1"; vbCrLf; "txtField1";
        
    For 1 To UBound(V)
            Print 
    #F, Application.Rept(vbCrLf & V(R, 2), V(R, 1));
        
    Next
            Close 
    #F
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Registered User
    Join Date
    05-18-2009
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Hi ! Try this ‼

    Hi Marc,
    Thanks for your help! This works perfectly!
    Is it possible for slight modification to the code to allow multiples files to be saved? For example, i will run the macro and it creates the Applied1.csv file. But if I change the quantities and data fields and re-run the macro, it replaces the first file with the new data. Is it possible to not overwrite the first file and save multiple files?

  5. #5
    Valued Forum Contributor
    Join Date
    01-14-2013
    Location
    Austria
    MS-Off Ver
    2016 / 2019
    Posts
    339

    Re: Macro to Create Individual Records from List with Qtys

    may be the attachment contains your solution

    cheers
    Guenter
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-18-2009
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Hi ! Try this ‼

    Hi Marc,
    A few years ago, (Jan 2020), you helped me with a Macro in this thread. I've been using it for 3 years with much success, it works very well!
    I now have a need to repeat 2 columns of data. Before, it was Col A - Qty. Col B - Data. Data to repeat on number of lines as qty shown. If I try the old Macro here, it doesn't work.
    Attached files showing sample data & what I want as result. Thanks!

    Quote Originally Posted by Marc L View Post

    An Excel 2003 beginner VBA starter demonstration (in fact works whatever the version !) :

    PHP Code: 
    Sub Demo1()
        
    Dim VF%, R&
            
    ActiveSheet.UsedRange.Columns("A:B").Value2
            F 
    FreeFile
            Open ActiveWorkbook
    .Path Application.PathSeparator "Applied1 .csv" For Output As #F
            
    Print #F, "Applied1"; vbCrLf; "txtField1";
        
    For 1 To UBound(V)
            Print 
    #F, Application.Rept(vbCrLf & V(R, 2), V(R, 1));
        
    Next
            Close 
    #F
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !
    Attached Files Attached Files

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

    Lightbulb Hello, try this ...


    Thanks to well read this time the advise just below the code …

    According to your last attachment another starter VBA demonstration :

    PHP Code: 
    Sub Demo2()
        
    Dim VF%, R&
            
    Sheet1.UsedRange
            F 
    FreeFile
            Open ActiveWorkbook
    .Path Application.PathSeparator Sheet1.Name " .csv" For Output As #F
            
    Print #F, Sheet1.Name; ","; vbCrLf; V(1, 2); ","; V(1, 3);
        
    For 2 To UBound(V)
            Print 
    #F, Application.Rept(vbCrLf & V(R, 2) & "," & V(R, 3), V(R, 1));
        
    Next
            Close 
    #F
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

+ 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. Create Individual forms for Employee from list
    By kvargas17 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-14-2018, 01:21 PM
  2. [SOLVED] Macro to print all individual records
    By vwlibra in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-10-2016, 12:28 AM
  3. How do I create a macro that will split my spreadsheet into individual files?
    By DJ3679 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2014, 07:02 PM
  4. How do I create a macro that will split my spreadsheet into individual files?
    By DJ3679 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2014, 03:20 PM
  5. [SOLVED] Create a list with all records with the same username in a database.
    By bill6432 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-01-2012, 01:13 PM
  6. Create list of unique records
    By SueWithQuestion in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2010, 10:19 AM
  7. macro code to print all or individual records
    By sujittalukder in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-12-2007, 08:54 AM

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