+ Reply to Thread
Results 1 to 12 of 12

Export to CSV rows populated

  1. #1
    Registered User
    Join Date
    06-14-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    13

    Export to CSV rows populated

    Hi,

    I'm looking for some help with my problem. I want to export the data I have in the sheet through a button.

    I have 6 columns from A to F.

    In the column name I have the country name or Language, from row 6 to below. If the A column contain any keywords I want that entire line to be exported to a CSV file.
    The idea is to have a vba button on the sheet and when clicked, it would export ALL lines from row 6 to below that contain any keywords in the column A.

    If column A does not contain any keywords/blank, then ignore that line and do not export.

    This is my excel file:
    excel_data.png

    Output should be similar to this:
    output.png

    Can anyone help?

    Thanks

  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: Export to CSV rows populated

    You can apply an Autofilter to row5, then filter the data by column A for all rows that "<>" (not blank), that would hide all the blank rows. Then copy all visible rows to a new sheet, then save that sheet as a CSV. All pretty standard.

    1) What is the path to save the CSV?
    2) What is the name of the CSV each time it is saved? Is it the same each time, or should it increment in some manner?
    3) Will column F always have data in every row? It's important the answer is "yes" if a simple autofilter approach is to work correctly.


    It would be much simpler to help directly if you post your workbook. Click GO ADVANCED and use the paperclip icon to attach your sample workbook.
    _________________
    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
    06-14-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Export to CSV rows populated

    1 and 2) Ideally it would go to the root folder where this file is create a folder "Lists" with the names "uk.csv" and "us.csv" (different tabs on the excel)
    Just need it to save the file each time I click on the button.

    3) Colum F will always have data.

    CL1.xlsm

    The problem is that using the auto filter wont eliminate the blank rows when exported.

    Thanks

  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: Export to CSV rows populated

    You can put this macro into a standard code module (Insert > Module).
    Then connect all your buttons on each of the sheets to the same macro, it will work for each and name each CSV for the same name as the sheet from which it is triggered.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-14-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Export to CSV rows populated

    Hi JBeaucaire,

    That works! I only have some last questions.

    1) I am using some formulas now to pull the values you see in the data. So, the country, name etc are pulled from other sheets onto the applicable country ones such as USA , UK etc.
    When I use this code without the formulas it works, but with the formulas I get this behavior: error.png

    2)In my original file I have nearly 40 tabs (I know its crazy). 30 of them are the ones that I want the data to be pulled and they all start with the word "Scenario", as in "ScenarioUSA" , "ScenarioUK" and so on.
    Is it possible to run this code only in the tabs that start with the word "scenario" in my entire workbook?

    Thanks in advance,

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

    Re: Export to CSV rows populated

    1) Change this:
    Please Login or Register  to view this content.
    2) I thought I saw a button on the pages where you wanted this to run. Won't you just be clicking your button on any given page to run it?

  7. #7
    Registered User
    Join Date
    06-14-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Export to CSV rows populated

    Had to use xlPasteValuesAndNumberFormats as the date format was coming as 4144, but thanks for the hint! It helped.

    2) I started with just a few tabs, hence my initial idea of clicking in a few buttons on every tab worked. But now has developed to 30 tabs and makes it time consuming to go through all and clicking the tabs to export the data. Is it possible to do a main button to use this code on all tabs that have a name that starts by "Scenario.."?

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

    Re: Export to CSV rows populated

    Please Login or Register  to view this content.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Last edited by JBeaucaire; 04-19-2014 at 07:16 PM. Reason: Corrected naming method.

  9. #9
    Registered User
    Join Date
    06-14-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Export to CSV rows populated

    Sorry JBeaucaire, I am still getting an error message when I try to run the script "run-time error '1004' method 'saveas' of object '_workbook' failed".

    When I hit the debug it shows me that the error is in this line:
    ActiveWorkbook.SaveAs fPATH & fNAME & ".csv", FileFormat:=xlCSV, CreateBackup:=False

    What could it be?.. Thanks

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

    Re: Export to CSV rows populated

    My bad, I meant to move the naming variable within the FOR/NEXT loop and just forgot. Corrected above, grab that code again.

  11. #11
    Registered User
    Join Date
    06-14-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Export to CSV rows populated

    Thank you!! That worked like a charm :D

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

    Re: Export to CSV rows populated

    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above to mark a thread as SOLVED. Thanks.

+ 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. [SOLVED] Printing populated rows only
    By pbutche in forum Excel General
    Replies: 8
    Last Post: 02-07-2014, 06:22 PM
  2. [SOLVED] Trying to write a Loop to perform calculations within blank rows between populated rows
    By ObliviousAmI in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-15-2014, 06:35 PM
  3. [SOLVED] Counting populated rows
    By Journeyman3000 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 11-19-2013, 10:26 AM
  4. How do I export populated cells to a TXT file
    By Tworsey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2011, 10:55 AM
  5. how to count populated rows?
    By Ryan Cain in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 08-12-2005, 12:05 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