+ Reply to Thread
Results 1 to 4 of 4

Thread: Create text file named A1 with B1 and C1 for multiple rows

  1. #1
    Registered User
    Join Date
    01-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    50

    Create text file named A1 with B1 and C1 for multiple rows

    Hi All,

    Say I have:
    Column A: email address
    Column B: 6 digit number
    Column C: 4 digit number

    I want a macro or VBA to create 1 text file for each cell in column A with the data from column B and C for the corresponding cells (e.g. A1.txt containing B1 C1)

    This seems simple, but I can't figure out how to do it. I tried a search and I'll admit, I'm not very good with macros or with VBA much at all, but I want to learn. This is the first application I need. Let's assume I don't have python or anything else to work with, just excel 2010.

    Any help is greatly appreciated!

  2. #2
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Create text file named A1 with B1 and C1 for multiple rows

    Hi

    how about

    For Each ce In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        Open ce & ".txt" For Output As #1
        Write #1, ce.Offset(0, 1) & " " & ce.Offset(0, 2)
        Close #1   
    Next ce
    rylo

  3. #3
    Registered User
    Join Date
    01-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Create text file named A1 with B1 and C1 for multiple rows

    Quote Originally Posted by rylo View Post
    Hi

    how about

    For Each ce In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        Open ce & ".txt" For Output As #1
        Write #1, ce.Offset(0, 1) & " " & ce.Offset(0, 2)
        Close #1   
    Next ce
    rylo
    Thanks. I will try this when I get to work this morning and report back
    Appreciate the help!

  4. #4
    Registered User
    Join Date
    01-30-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    50

    Thumbs up Re: Create text file named A1 with B1 and C1 for multiple rows

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    ' Keyboard Shortcut: Ctrl+q
    '
    For Each ce In Range("A1:A" & Cells(Rows.Count, 1).End(xlDown).Row)
        Open ce & ".txt" For Output As #1
        Write #1, ce.Offset(0, 1) & " " & ce.Offset(0, 2)
        Close #1
    Next ce
    End Sub
    had to edit the code a bit, but it worked perfectly! So much thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0