+ Reply to Thread
Results 1 to 3 of 3

Print Multiple Ranges to a Text File

Hybrid View

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Print Multiple Ranges to a Text File

    Howdy,

    New member here, very little experience with VB and it's been years since I used to program in QuickBasic. Joined this forum to get help and to help out if I can:

    I need to copy some cells in my Excel file to a text file. I searched here and found something which almost works but for some reason it's not getting all the cells I need. In fact it copies the first two cells (D5 & D6) which are in the first range list, and then it writes the last item in the list (I17). Everything else in between is omitted. Can anyone tell me what I need to correct here?

    Sub makeFile()
    Dim ce As Range
    Open "c:\0\junktesting.txt" For Output As #1
    For Each ce In Worksheets("My_Sheet1").Range("D5:D6,D8,D12:D19,D21,D23:D27,D29:D30,D32:D33,D35,D38:D39,I17")
    Write #1, ce.Value
    Next ce
    Close #1
    End Sub
    Last edited by Vladamir; 01-13-2012 at 06:00 AM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,355

    Re: Print Multiple Ranges to a Text File

    Hi Vladamir and welcome to the forum,

    I'm wondering if the "Write #1, ce.Value" is the problem? Try leaving off the ".Value" and see what happens. I believe there is a "ce.Text" that will only send/capture cell stuff that is Text.

    Hope this helps.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Re: Print Multiple Ranges to a Text File

    Thanks very much for your reply. I found the error. The cell column was incorrect. My bad, but thanks all the same my friend.
    Last edited by Vladamir; 01-12-2012 at 12:41 PM.

+ 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.6.0 RC 1