+ Reply to Thread
Results 1 to 7 of 7

VBA macro to export specific range of cells to CSV

  1. #1
    Registered User
    Join Date
    03-23-2016
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Microsoft Office Professional 2010
    Posts
    4

    Question VBA macro to export specific range of cells to CSV

    Hey everyone,

    I am trying to export specific range of cells from excel sheet to CSV. In my case it should start from Row 3 and stop with last row and columns should be A:G

    I am pretty amateurish with VBA so most of things I google and compile yet, but im stuck at this moment.

    Ive got below macro but it exports whole sheet and I need to skip first 2 rows and stop at column G.

    Thank you guys in advance

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA macro to export specific range of cells to CSV

    Hi and welcome to the forum.

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    03-23-2016
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Microsoft Office Professional 2010
    Posts
    4

    Re: VBA macro to export specific range of cells to CSV

    Hi thank you, it returned an error for the row " Rows("1:2").Delete "

    Anyways, meanwhile I found your code (below) in another topic which gives me csv export for cell range I choose, which is great. But I would like to change the path and filenames for exports generated:
    Is there a way to create new folder in a specific path so It places the file in folder for current date (ddmmyyyy) or it creates one if there is none?
    Can the file be named based on a specific cell in excel?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-23-2016
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Microsoft Office Professional 2010
    Posts
    4

    Re: VBA macro to export specific range of cells to CSV

    figured it out find below how I updated the code

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA macro to export specific range of cells to CSV

    Quote Originally Posted by branys View Post
    figured it out find below how I updated the code

    Please Login or Register  to view this content.

    Well done.

    FYI: you could replace this...
    Shell ("cmd /c mkdir """ & MyPath & """")

    With this...
    MkDir MyPath

  6. #6
    Registered User
    Join Date
    03-23-2016
    Location
    Bratislava, Slovakia
    MS-Off Ver
    Microsoft Office Professional 2010
    Posts
    4

    Re: VBA macro to export specific range of cells to CSV

    I have one more question to this topic..

    Is there a way to improve my macro to export only values in csv? in some cells there are formulas and it will export #values error..

    Thank you!

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA macro to export specific range of cells to CSV

    Change this...
    .Sheets(1).Paste

    To this...
    .Sheets(1).Range("A1").PasteSpecial xlPasteValues

+ 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. macro to print a specific range of cells
    By shortnewb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-16-2018, 10:05 AM
  2. Export pdf from specific Range of cell throug loop
    By rohankumarkshirsagar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2015, 04:02 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. [SOLVED] Consolidation Macro with specific range/area of cells
    By acasas44 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2013, 10:35 AM
  5. [SOLVED] Macro to export range of cells to notepad file.
    By MrIdontknowexcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-28-2012, 03:17 PM
  6. [SOLVED] Macro to Specific Cells in a Range
    By Magnivy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2006, 01:10 PM
  7. Macro to Select Specific Cells in a Range
    By Magnivy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2006, 12:25 PM

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