+ Reply to Thread
Results 1 to 24 of 24

VBA Assistance - Export CSV with Version number

  1. #1
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Question VBA Assistance - Export CSV with Version number

    Hello Excel Experts,

    I have a bit of a problem - and I have 75% of the solution.

    I have an excel sheet that I am using to save certain values when entered into a CSV and I am using a formula in the cells to produce the sheet only if a cell has a value.

    I actually have 2 VB Macros that I found and both seem to work but give different results. The first VB script works great for the version counting but it displays many ,,,,,, at the end of the file.

    That VB looks like this
    Please Login or Register  to view this content.
    The second which is a much simpler script gets me the output I am looking for and only looks to the cells that actually have values entered and skips over the ones with the formula =IF(ISBLANK(...) etc.

    That code is
    Please Login or Register  to view this content.
    My question is how can I get the best of both worlds here and get the script to just pull the values like in VB 2 but still save using the _Vx version counting saving.

    Thank you so much as always in advance.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    Try this version.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    Thank you for your reply and help with this.

    I tested out your macro, and it seems to work only on the sheet where the user enters the data that they want to configure. On the 2nd sheet where I have my formula, when I run the macro, it does not see the formula values (which is good) but it also does not see the values being added from where the user enters the data.

    Secondly, your script does not present the user with a popup displaying the version number that was created.

    And how can the file be saved to the same directory that the .xlsm is being launched from?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    In order for me to adjust the macro, you will need to a post the workbook.

  5. #5
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    No problem. Thanks for your help with this.

    The sheet itself is very basic with only 4 columns necessary for the user to enter their 3 bids (on sheet 1).

    Sheet 2 contains the formula and where I am attempting to generate the csv from with that specific format and order.
    Attached Files Attached Files
    Last edited by dice1976; 03-29-2016 at 11:51 PM.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    Thanks for downloading the file. This will makes it much easier to get right.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    I think this macro does what you want. Let me know if it does not. It has been added to the attached workbook and assigned to the button "Create CSV File".

    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    Thank you for this... This one though has a run-time error Path/File access error

    When I debug- the highlighted row shows:
    Open FolderPath & FileName For Output As #1
    Print #1, Text
    Close #1

    Also in the below is FileParh correct or that should read FilePath = ThisWorkbook.Path ?
    FileParh = ThisWorkbook.Path
    FileName = Sheet2.Name
    Last edited by dice1976; 03-30-2016 at 09:40 AM. Reason: added FileParh part

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    Sorry, that was my fault due to a spelling error. Here is the new code. It also shows the full file path.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    Okay so it runs now with no error- but your macro vb is pulling the data from sheet 1 and not from sheet 2 whereas in sheet 2 is the specific exact format that the csv needs to be in and sheet 1 is the data entry page.

    Also- the exported csv file is taking the name of "sheet2" and not the open file name.
    Last edited by dice1976; 03-30-2016 at 12:07 PM. Reason: paragraph 2

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    Did you replace the old macro code with the new or did you simply update it?

    The old code used Sheet1. The new code uses Sheet2. The macro uses the code name Sheet2 to access "Sheet2". Using the code name allows you to change "Sheet2" to what you want to name it while the code uses the code name which does not change.

  12. #12
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    I inserted the macro code as a new module and when I run it on sheet 1 - it exports sheet 1 with that data on sheet 1 (in correct format for my csv).

    When I run the macro and I am on sheet 2 - the export is blank.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    Thanks for telling me about switching the sheets. I found what is wrong and I am working to fix it.

  14. #14
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    Here is the working macro - guaranteed. I have also attached the workbook just in case.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    Thank you for this! 99.99% of the way there.

    This does give me the export of the data in csv with the correct format- but is there any way to not have all the enters or extra lines at the bottom- so if one were to enter 4 or 5 items, the csv is showing 100 lines.

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    All the blank lines will look like ",,,,". Is that what you want? If so, the code below will do that. The part that has been changed is in blue.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    Hi- no that's not exactly what I meant.

    For example, in the 1st post, the 2nd script does the export of data into CSV but will only export the rows that actually have values. So, if there are 4 rows, then the CSV has only 4 rows.

    In the working script you provided, it works similar where the 4 rows are the only ones to print, and the ,,,, is correctly left off of the rest of the rows following, but I end up with 96 blank lines in the CSV instead of only 4 or 5 lines in the CSV.

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    I cannot duplicate your problem. If I open a CSV created by the macro in either Excel or NotePad there are only 4 rows of data, not 100.

  19. #19
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    AH HA! "NOTEPAD"

    So, I was looking at all these csv files in Notepad++

    If I open up the exported CSV in plain-old-windows-lame Notepad, then I can verify that I do see the expected output of 4 lines only.

    Thank you so much for all your help with this. I think I should be good to go with my file transfer.
    Attached Files Attached Files

  20. #20
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    Glad we got that figured that out. Just out of curiosity, why were you using Notepad++ ?

  21. #21
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    I had notepad++ open because I have some dos batch file scripts I was running and I like the use of the tabbed interface vs. notepad (no tabs, no format, nothing)

  22. #22
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    Last (quick) question- say I wanted to start at V01 and count up instead of V1- is that an easy change ?

  23. #23
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA Assistance - Export CSV with Version number

    Hello dice1976,

    It has been a busy day. My daughter's truck is having problems starting and that has taken up most of my day.

    Yes, it is an easy fix. Change the line below...

    From
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    03-30-2011
    Location
    new york
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    20

    Re: VBA Assistance - Export CSV with Version number

    Thank you again so much. And good luck with your daughter's truck. If I had any mechanic skills I'd offer help to return the favor.

+ 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] How to find version number
    By 1eyedjack in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 03-24-2016, 12:17 PM
  2. Formulas not working in higher version, 2010 Version to 2013 version
    By thilag in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-19-2015, 09:09 PM
  3. [SOLVED] Find highest version number for each material number
    By keld.strobel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-06-2015, 07:08 AM
  4. [SOLVED] Export Excel Tab to PDF. Macro Assistance Request!
    By spiwere in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 07-04-2013, 01:41 PM
  5. Macro assistance needed for complex export/import excel file
    By dedavie in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2013, 02:47 PM
  6. Replies: 1
    Last Post: 03-01-2008, 11:05 PM
  7. Save As with Version Number
    By ssjody in forum Excel General
    Replies: 3
    Last Post: 12-17-2006, 08:41 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