+ Reply to Thread
Results 1 to 14 of 14

How to save Excel file to csv with blank cells with formula with out getting commas.

  1. #1
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    How to save Excel file to csv with blank cells with formula with out getting commas.

    Hello every one!

    I am working on a excel file that has a sheet that i want to convert to .csv. The sheet has formula's for the first three column that are warped an if statement that returns "" (blank) if certain conditions are not meet. However when i got to save the file as a csv i get a file with ",,,,,,," where there is no data.
    I would like to save csv and have only commas where this data.
    Example
    When i convert a sheet like
    Firstname Lastname Password
    Tim Cats Bo3n9x

    it saves as
    Firstname Lastname Password
    Tim Cats Bo3n9x
    ,,,
    ,,,
    ,,,

    In the .csv file.

    Files i am current working on are attached.
    Any help would be much appreciated!

    If there is any other info you would need let me know.
    Attached Files Attached Files
    Last edited by xizor; 04-08-2014 at 06:32 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    I suggest you copy the sheet. On the copy of the sheet, select all the cells and copy and paste special | values ... or simply delete the "blank" rows. Then save the copied sheet as a .csv file. Delete the copy sheet if it is no longer required.

    If you do it often, record the actions as a macro.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    Quote Originally Posted by TMS View Post
    I suggest you copy the sheet. On the copy of the sheet, select all the cells and copy and paste special | values ... or simply delete the "blank" rows. Then save the copied sheet as a .csv file. Delete the copy sheet if it is no longer required.

    If you do it often, record the actions as a macro.

    Regards, TMS
    Thank you for your reply. I am currently trying to do you have suggested, copying and pasting special |values to a blank sheet then opening the .csv with not pad and it is still showing with ",,,," inside the .csv file down the file.
    I have double checked the cells to make sure there are no formula's in them. I have tried to special past the values in a completely new work book but i still get the same results?

    I much appreciate the assistance!

    Regards,
    Xizor

  4. #4
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    Quote Originally Posted by xizor View Post
    Thank you for your reply. I am currently trying to do you have suggested, copying and pasting special |values to a blank sheet then opening the .csv with not pad and it is still showing with ",,,," inside the .csv file down the file.
    I have double checked the cells to make sure there are no formula's in them. I have tried to special past the values in a completely new work book but i still get the same results?

    I much appreciate the assistance!

    Regards,
    Xizor
    Any other suggestion from anyone?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    OK, have a look at the attached workbook. It takes a lightly different approach. It uses a Worksheet Change event to monitor input on the Request Guest worksheet and, when all four columns/cells are completed, it generates the formulae on the Guest Wifi Template worksheet. It then converts the fomulae to values and save the Guest Wifi Template worksheet as a .csv file.

    So, every time you add or change a row on the Request Guest worksheet, it will generate a complete new list. Note that it only re-generates codes if you make changes to a row. It doesn't have cells with "empty" formulae so it doesn't generate rows with just commas.

    Regards, TMS
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    Quote Originally Posted by TMS View Post
    OK, have a look at the attached workbook. It takes a lightly different approach. It uses a Worksheet Change event to monitor input on the Request Guest worksheet and, when all four columns/cells are completed, it generates the formulae on the Guest Wifi Template worksheet. It then converts the fomulae to values and save the Guest Wifi Template worksheet as a .csv file.

    So, every time you add or change a row on the Request Guest worksheet, it will generate a complete new list. Note that it only re-generates codes if you make changes to a row. It doesn't have cells with "empty" formulae so it doesn't generate rows with just commas.

    Regards, TMS
    This is amazing! Thanks. I am not to well versed in VBA but i am going to study what you have provided so that i know exactly how it works.
    This is very much appreciated thanks!

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    You're welcome. Thanks for the rep.


    I guess there might have been another way, but I tried a few options with your data and, despite copying and pasting values, etc., it still had all those rows of commas. Hopefully, it's something to work with and build on.

    Regards, TMS




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  8. #8
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    quick question to before we wrap this up.
    How can i make edits to columns headers first name last name company with out breaking the code?

  9. #9
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    Also it seems that the Worksheet Change event has stopped working. When I go to add or delete guest it does not update template page. I have been searching for why that is, and one lead I have found is that Application.EnableEvents maybe disabled. But i am not sure how to turn it back on for this even?
    Last edited by xizor; 04-01-2014 at 06:13 PM.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    Please Login or Register  to view this content.

    Regards, TMS

  11. #11
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    Quote Originally Posted by TMS View Post
    Please Login or Register  to view this content.

    Regards, TMS
    Thanks for all your help! This has been a great help and an awesome learning experience. If I can bug you a little bit more, I am putting finishing touches on the work book and running into a few errors and wanted to see if you have any suggestion on where I am going wrong at?

    In column C row 1 on Guest wifi template page the date is not populating. (Screen shot attached.) missing date in row c.PNG

    The code no longer updates for the Guest Wifi Template page when I add or delete users in each cell on the Request Guest sheet.

    I have trying adding the Application.EnableEvents = Ture to the Immediate window and to vba code but this seems to not have resolved the issue.

    Also i wanted to clean up the headers section of Request guest sheet, but when i change the names of the headers i get an Run time error '1004' Application defined or Object defined error. (screen shot attached.)excel error.PNG
    excel vba error.PNG

    Let me know if there is anything else I can provide. Again I thank you for all your help!

    Regards,
    Xizor

    Guest Wifi Access Generator TMS.xlsm

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    The date in column C is dependent on the formula that you use. I just drop that formula in and convert the result to a value. If you want to see what formula is going in there, comment out the ".Value = .Value" line of code. You can then evaluate the formula.

    That said, I just selected cell A2 and pressed F2 (to go into Edit mode) and then Enter (to recommit the value [Manchester]) and it generated the date value.

    The code doesn't actually disable Event handling because it doesn't make any changes on the sheet where the event is being trapped. I note that you have spelt "True" as "Ture" both in your post and in the code:

    Please Login or Register  to view this content.

    I guess the reason that you are having problems changing the headings is that the Change Event handler is monitoring the entire columns A to D. Open the workbook without enabling macros, make the changes to your headings and then save the workbook. Open it again, this time enabling macros.

    Note: what is happening is that the code uses a variable, tr, for the Target Row. Because the csv doesn't have headers, the row is adjusted using the variable trm1 ... Target Row Minus 1. So, if you try to change row 1 on the Template sheet, the code is trying to write to row 0 which doesn't exist.


    Regards, TMS
    Last edited by TMS; 04-01-2014 at 07:58 PM.

  13. #13
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    First things first i correct the typos in the code.

    The date in column C is dependent on the formula that you use. I just drop that formula in and convert the result to a value. If you want to see what formula is going in there, comment out the ".Value = .Value" line of code. You can then evaluate the formula.
    This bit was key for me as i understand what is happening now after commenting out this line. The function:
    =If('Request Guest!D2="","",MAX(0,'Request Guest'!D3-Brain!B$2)*86400) is not being iterated. !D3 inside MAX(0,'Request Guest'!D3-Brain!B$2)*86400) is not changing to !D4, D5, D6 etc.. Do i need to make another formula for the change event?




    I guess the reason that you are having problems changing the headings is that the Change Event handler is monitoring the entire columns A to D. Open the workbook without enabling macros, make the changes to your headings and then save the workbook. Open it again, this time enabling macros.

    Note: what is happening is that the code uses a variable, tr, for the Target Row. Because the csv doesn't have headers, the row is adjusted using the variable trm1 ... Target Row Minus 1. So, if you try to change row 1 on the Template sheet, the code is trying to write to row 0 which doesn't exist.
    This allowed me to fix the headings and I understand the error now.

  14. #14
    Registered User
    Join Date
    03-20-2014
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to save Excel file to csv with blank cells with formula with out getting commas.

    Quote Originally Posted by TMS View Post
    The date in column C is dependent on the formula that you use. I just drop that formula in and convert the result to a value. If you want to see what formula is going in there, comment out the ".Value = .Value" line of code. You can then evaluate the formula.

    That said, I just selected cell A2 and pressed F2 (to go into Edit mode) and then Enter (to recommit the value [Manchester]) and it generated the date value.

    The code doesn't actually disable Event handling because it doesn't make any changes on the sheet where the event is being trapped. I note that you have spelt "True" as "Ture" both in your post and in the code:

    Please Login or Register  to view this content.

    I guess the reason that you are having problems changing the headings is that the Change Event handler is monitoring the entire columns A to D. Open the workbook without enabling macros, make the changes to your headings and then save the workbook. Open it again, this time enabling macros.

    Note: what is happening is that the code uses a variable, tr, for the Target Row. Because the csv doesn't have headers, the row is adjusted using the variable trm1 ... Target Row Minus 1. So, if you try to change row 1 on the Template sheet, the code is trying to write to row 0 which doesn't exist.


    Regards, TMS
    So I have been playing around with the code for
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    to try to get
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    to change to
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    but i can not seem to get this part
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    to change iterate to the next cell.

    I have tried other functions as well, but none iterate!D3.

    I was thinking that maybe the function only iterates the first part "=IF('Request Guest'!D" & tr & "="""","""", and that maybe I need to use code for MAX(0,'Request Guest'!D4-Brain!B$2)*86400) to make it go to the next number? But I am sure where to begin?

+ 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. Replies: 9
    Last Post: 11-23-2016, 12:22 PM
  2. Blank cells but commas in Notepad
    By john_mc in forum Excel General
    Replies: 8
    Last Post: 07-02-2015, 04:42 PM
  3. [SOLVED] Remove blank cells from row, add commas between data in new cell
    By michellewayside in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 01-13-2014, 02:49 PM
  4. Output CSV file creates commas down blank rows
    By mcinnes01 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2010, 05:54 AM
  5. Save in Excel with Commas
    By ftstrader in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-16-2009, 08:24 PM

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