+ Reply to Thread
Results 1 to 7 of 7

Export range to CSV not copying data

  1. #1
    Registered User
    Join Date
    11-09-2011
    Location
    Brighton, UK
    MS-Off Ver
    Excel 2010 & Office 365
    Posts
    41

    Export range to CSV not copying data

    Hi All,

    I am a bit stuck...! I have created a macro that is copying a range of data to a new CSV file, naming and closing it, but even though it seems to work, when the file is opened there is no data in it at all.
    When I step into the code, the data appears in the new file, then just as quickly disappears and is never seen again. Any help greatly appreciated....

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    11-09-2011
    Location
    Brighton, UK
    MS-Off Ver
    Excel 2010 & Office 365
    Posts
    41

    Re: Export range to CSV not copying data

    The code seems to hang on the paste part. When it is running, there is a message in the bottom left corner (hit enter to paste)
    I added in the line

    Please Login or Register  to view this content.
    and that has not helped either...

    I also ran a check on the CutCopyMode with the following:

    Please Login or Register  to view this content.
    and it declared 1 (for copy) each time! Surely I must be missing a trick somewhere...!
    Last edited by witham; 11-21-2014 at 09:01 AM. Reason: attempted & failed fix

  3. #3
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Export range to CSV not copying data

    I havent tried your full code but add this
    Please Login or Register  to view this content.
    after this

    Please Login or Register  to view this content.
    it will remove the message at the bottom.
    The above code worked fine to copy the data, open a new workbook and paste the data
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

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

    Re: Export range to CSV not copying data


    Hi,

    better to trying to undestand something to your code, attach a source xlsx workbook (no macro)
    and a desired result text file according exactly from this source file …

    Edit : Sean was fastest … but I 'll create new workbook first and then copy at once with only one instruction !
    Or I directly write text file without the need of a new workbook …
    Last edited by Marc L; 11-21-2014 at 11:21 AM.

  5. #5
    Registered User
    Join Date
    11-09-2011
    Location
    Brighton, UK
    MS-Off Ver
    Excel 2010 & Office 365
    Posts
    41

    Re: Export range to CSV not copying data

    Hi Sean & Marc,

    I added in the
    Please Login or Register  to view this content.
    and it doesn't do anything extra, but thanks for the suggestion.
    I have created the file as an .xlsx file and what needs to happen is simply the data in the worksheet "DEFECTS" is extracted and stored as a separate file in CSV format with the filename specified in the worksheet PROJECTS D3.

    The file is created fine and I cannot see anything wrong with the code as it is, but the data just vanishes as soon as it pastes.DEFECT-TRIAL.xlsx

    I will try a re-write to create the workbook then copy across the data and let you know how I get on, but thanks for your input so far!
    Last edited by witham; 11-24-2014 at 11:51 AM. Reason: Updated.

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

    Re: Export range to CSV not copying data


    A good code doesn't use Activate, Select

    Working on my side : code to copy worksheet in a new workbook and save as csv text file before closing it :
    Please Login or Register  to view this content.
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Registered User
    Join Date
    11-09-2011
    Location
    Brighton, UK
    MS-Off Ver
    Excel 2010 & Office 365
    Posts
    41

    Re: Export range to CSV not copying data

    Thanks Marc,
    That works like a dream. And thanks for the good code lesson. It's great to get better as well as achieve my aim!
    Thanks for your input too Sean.

+ 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. export excel range data populate to word bookmark
    By hyn1999 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 05:01 AM
  2. export data by selecting date range
    By amy chan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-07-2013, 12:32 AM
  3. Macro to export specific range of data to text file for each worksheet
    By sonofamonkey10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2013, 05:43 PM
  4. copying a range to first empty row is copying over data
    By jseufert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2009, 03:45 AM
  5. Replies: 0
    Last Post: 01-11-2006, 11:00 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