+ Reply to Thread
Results 1 to 5 of 5

Macro to create text file and write contents of selected cells to the file

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    Madison, WI
    MS-Off Ver
    Excel 2010
    Posts
    3

    Macro to create text file and write contents of selected cells to the file

    Hello,

    I need some help writing the contents of specific cells to a newly created text file that's named with the contents of a cell. (That doesn't sound very clear, does it?) I'll explain. I have a large worksheet with data in multiple rows and columns A-J. The macro will prompt the user to select a cell and then create a text file using the contents of the cell as the name. This part works fine based on some code I found on other sites. The next step is to write the contents of the same sell into the file along with the contents of cells D and F in the same row, separated by commas. I can get the contents of the first cell written but when I try to write the contents from another cell the file ends up being blank. I'm not sure if it's how I'm declaring the other variables or what. This is the portion I have working correctly.

    Please Login or Register  to view this content.
    Any help or pointers would be much appreciated.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to create text file and write contents of selected cells to the file

    Like so:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-13-2013 at 10:16 AM. Reason: Added error/exit trap
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-23-2012
    Location
    Madison, WI
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to create text file and write contents of selected cells to the file

    That works great, thank you!
    One related follow-up. If the user hits the "Cancel" button in the Input box it generates 424 error: Object required. How would I prevent that? I tried putting
    Please Login or Register  to view this content.
    before the Set MyCell statement but that generates a different error, '91'.
    I can live without it but just wondering if you know.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to create text file and write contents of selected cells to the file

    Fixed above in the original code.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Thanks.

  5. #5
    Registered User
    Join Date
    10-23-2012
    Location
    Madison, WI
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to create text file and write contents of selected cells to the file

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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