+ Reply to Thread
Results 1 to 31 of 31

How to remove quotations " from an auto generated file?

  1. #1
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    How to remove quotations " from an auto generated file?

    Hi all,

    Hope all are doing well.

    A bit unusual request this time. Attached file contains a macro which when run based on certain conditions generates 2 CSV files namely import_alert_status_change_template and import_investigation_status_change_template.

    Out of the 2 CSV files, 2nd one has no issues and even the 1st one doesn't show any issues unless its investigated thoroughly. To elaborate, CSV file import_alert_status_change_template has " at the beginning and end of most cells. The same can be seen when the file is opened in Notepad++ application as shown in snip below.

    Is there any way that these " can be removed either by modifying code in MSTool file or by creating another macro such that when its run, it shall ask to select the file and thereafter shall remove all the " in it thereby saving it? Currently i have to open the file in Notepad++ each time and use replace option.

    Can someone please help ?

  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
    46,963

    Re: How to remove quotations " from an auto generated file?

    I suspect it is something to do with your Regional Settings. Neither of the csv files shows double quotes for me.

    I think this happens if the cell values contain the character that is used as the delimiter.
    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
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    Since CSV is essentially a text file, you can process it before you import it or after you've created it.

    Please Login or Register  to view this content.
    To usage, pass your file to it at a point before importing it.
    Please Login or Register  to view this content.
    Last edited by ByteMarks; 10-30-2024 at 10:58 AM.

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    Quote Originally Posted by TMS
    Neither of the csv files shows double quotes for me.
    I see them only in the alert status file - inconsistantly, same as OP's image.
    They only appear in Notepad++. Normal Notepad (W10) and Excel don't show them.

  5. #5
    Registered User
    Join Date
    12-30-2020
    Location
    Here
    MS-Off Ver
    M365
    Posts
    63

    Re: How to remove quotations " from an auto generated file?

    CSV file consider "," as delimiter character,
    but in your alert file has "," charecter in the data value,
    so CSV file must distinguish the delimiter and "," value in the data,
    therefor the line has "," character in the data, must have double quotation.

    If you don't want double quotation, try TSV file instead, it's delimiter is horizontal tab.
    Last edited by mojirhi; 10-30-2024 at 11:13 AM.

  6. #6
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    Quote Originally Posted by ByteMarks View Post
    I see them only in the alert status file - inconsistantly, same as OP's image.
    They only appear in Notepad++. Normal Notepad (W10) and Excel don't show them.
    To be fair, I opened them in Excel. I'm using an iPad so no NotePad or NotePad++

  7. #7
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to remove quotations " from an auto generated file?

    Hi all,

    Many thanks for your responses. Greatly appreciate it.

    Sorry I didn't understand what needs to be done with code in post # 3.

    Just to explain briefly, the code in file MSTool, searches the IDs (before first semicolon) from Source file (attached) in target file Log - DACH (total 10 files) and generates 1 of the CSV files namely import_alert_status_change_template with result as below.

    ID;Under Investigation;RC-001;Pack active in ATTP, decommissioned elsewhere

    where Under Investigation and RC-001 are always constant

    Pack active in ATTP, decommissioned elsewhere is fetched from column AI in target file with reference to column AE in same file.

    Note: Files after generation are to be uploaded in a portal which accepts only CSV format. But I am unable to upload in portal since it gives error saying file contains ".
    Attached Files Attached Files
    Last edited by rizwanulhasan; 10-30-2024 at 12:32 PM.

  8. #8
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    After the CSV has been generated, call the ReplaceQuotes routine on it to remove the quotes.

  9. #9
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    As has been explained, you are creating a comma separated text file . . . and your data has commas in it. The tool is trying to protect the integrity of the csv file, hence the double quotes.

    I would have thought you could open the file in any text editor and do a global replacement of the double quotes by nothing (null).

    You might need to change the file extension from .csv to .txt, and back again after the edit.

  10. #10
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    @TMS didn't spot that or post #5 in which case don't replace the quotes.

    Maybe you need to replace any commas in the data with semi-colons during the data-build instead.

  11. #11
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    Quote Originally Posted by ByteMarks View Post
    @TMS didn't spot that or post #5 in which case don't replace the quotes.

    Maybe you need to replace any commas in the data with semi-colons during the data-build instead.
    Not necessarily. The fact that it is comma separated might be irrelevant to the target application.

    I can't see the code in the MStool. For all I know, it could be a single column and it could perhaps be saved as a text file. It actually looks as though the separator should be a semi-colon.

  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
    46,963

    Re: How to remove quotations " from an auto generated file?


  13. #13
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    I haven't worked out why notepad++ showed the quotes but standard notepad didn't.

  14. #14
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,209

    Re: How to remove quotations " from an auto generated file?

    Quote Originally Posted by rizwanulhasan View Post
    ... these " can be removed ... by modifying code in MSTool file ...
    Try to modify the 'CreateCSV' procedure in the second, inner 'For' loop for 'ii' variable:
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to remove quotations " from an auto generated file?

    Hi all,

    Thanks a bunch for getting involved and sharing the responses.

    @TMS:
    You are right. The text actually contains a comma between the statement

    Pack active in ATTP, decommissioned elsewhere

    @ByteMarks:

    I tried the code and it does remove the quotations . But does the file need to be always in a specified folder with a fixed name because the file name will change each day.

    @mjr veverka:

    Replaced the code and the generated file is without quotations in notepad++ . However, when i see in Excel, some text appears in second column instead of being a combination with text in first column. But i guess this will work. Let me try uploading in portal and revert.
    Attached Images Attached Images
    Last edited by rizwanulhasan; 10-30-2024 at 11:25 PM.

  16. #16
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    Again, it's a csv file with commas in the data. If you open in Excel it will split on the commas.

    The focus has been on getting rid of the double quotes. Instead, why don't you replace the commas in the raw data before you produce the export file? Either replace comma for, say, a hyphen. Or get rid altogether by replacing them with nothing.

  17. #17
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    Quote Originally Posted by rizwanulhasan
    @ByteMarks:
    I tried the code and it does remove the quotations . But does the file need to be always in a specified folder with a fixed name because the file name will change each day.
    You can just pass the path to the routine wherever it is, but as it turns out you really don't want to be doing this. Removing the quotes is why some text appears in second column instead of being a combination with text in first column.

    If the quotes are an issue, you want to replace/remove commas in the data, eg after Pack active in ATTP.

  18. #18
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to remove quotations " from an auto generated file?

    @TMS @ByteMarks:

    I replaced comma with hyphen in target file but that dint change anything in CSV file except that it no more shows comma. But i still have quotations in notepad++.
    Attached Images Attached Images

  19. #19
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    If there are now no commas in the data, you should be able to remove the quotes without it messing up the column split.

  20. #20
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    I can't see the code (on an iPad) but, are you actually inserting double quotes or is the export doing it? If you're doing it, don't. If the export is doing it, check what delimiter is being used.

    The code snippet in post #14 looks like a) the original code inserts double quotes, and b) the adjustment stops that happening.

  21. #21
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to remove quotations " from an auto generated file?

    @ByteMarks:

    One thing I am getting to know now is that maybe its not because of comma because I tried inserting hyphen and even removed comma. I entered value as Pack active in ATTP but decommissioned elsewhere in target file yet the generated CSV file has quotations. Its just that now its in single column instead of splitting into two.

    @TMS:

    I am not inserting any quotations but the code itself is generating a CSV file with quotations which can only be seen in notepad++
    Attached Images Attached Images

  22. #22
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to remove quotations " from an auto generated file?

    Hi both,

    Sorry but you were right. It was because of comma. Actually column AI had data validation. Although I removed comma, replaced with hyphen etc. and it appeared rightly in cell but looks like when macro was fetching data, it was considering data validation and pulling comma. Hence the CSV files showed quotations.

    Now I have chnaged all data validations in all files and looks like issue is solved. Also, the previous code was still showing quotations but the one in post # 14 works perfectly. I will test it again tomorrow and hope it doesn't give any problem.

    Meanwhile, a huge thanks to all of you for finding the root cause and providing the solution. Greatly appreciate your time and efforts

  23. #23
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,574

    Re: How to remove quotations " from an auto generated file?

    Happy to have contributed.

  24. #24
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    You're welcome. Thanks for the rep.


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  25. #25
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,209

    Re: How to remove quotations " from an auto generated file?

    Quote Originally Posted by rizwanulhasan View Post
    ... However, when i see in Excel, some text appears in second column instead of being a combination with text in first column ...
    Quote Originally Posted by TMS View Post
    ... it's a csv file with commas in the data. If you open in Excel it will split on the commas ...
    Data in the presented csv file is separated by a semicolon, not a comma.
    The problem is, on the one hand, the inappropriate places where quotation marks appear, and on the other hand, a different separator in the system (comma) than in the csv file (semicolon) - probably ... (?)

    There is:
    "DE-420a300e-282b-4edc-b745-fb2dc408a7a9;Under Investigation;RC-001;Pack active in ATTP, decommissioned elsewhere"

    ??? It should be ???:
    "DE-420a300e-282b-4edc-b745-fb2dc408a7a9";"Under Investigation";"RC-001";"Pack active in ATTP, decommissioned elsewhere"

    ??? or ???
    "DE-420a300e-282b-4edc-b745-fb2dc408a7a9","Under Investigation","RC-001","Pack active in ATTP, decommissioned elsewhere"

    You need to check in your regional settings what separator you have.
    Attached Images Attached Images

  26. #26
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    You need to check in your regional settings what separator you have.
    See posts #2 and #20, amongst others.

  27. #27
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,209

    Re: How to remove quotations " from an auto generated file?

    Ok TMS, but OP probably didn't do it.

    ... and ...

    Quote Originally Posted by rizwanulhasan View Post
    ... Note: Files after generation are to be uploaded in a portal which accepts only CSV format. But I am unable to upload in portal since it gives error saying file contains ".
    What kind of separators, delimiters are accepted by "this portal" ?
    ... or maybe ...
    What should the correct structure of the csv file for "this portal" look like ?

  28. #28
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to remove quotations " from an auto generated file?

    As identified and rightly suggested about comma, I modified all the target files and removed the comma. Now everything is working perfectly with the code provided in post # 14.

    Huge thanks to all. Wish you a great weekend

  29. #29
    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
    46,963

    Re: How to remove quotations " from an auto generated file?

    Quote Originally Posted by rizwanulhasan View Post
    As identified and rightly suggested about comma, I modified all the target files and removed the comma. Now everything is working perfectly with the code provided in post # 14.

    Huge thanks to all. Wish you a great weekend
    All credit it to mjr veverka then

  30. #30
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,209

    Re: How to remove quotations " from an auto generated file?

    ... but it's not "my code", it's just my "modification" of someone else's code ...
    Attached Images Attached Images

  31. #31
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to remove quotations " from an auto generated file?

    @mjr veverka:

    Greatly appreciate your modesty. But thanks a ton for the modification

    @jindon:

    The original maker of the code and one of the greatest geniuses i have ever come across. Hats off to you

+ 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. Remove double quotations from csv AND keep commas
    By erdayo in forum Excel General
    Replies: 0
    Last Post: 01-31-2021, 11:15 PM
  2. Collecting data from auto- generated excel file
    By nooredein in forum Excel General
    Replies: 6
    Last Post: 05-04-2014, 02:10 PM
  3. [SOLVED] VBA help needed to auto format date column and remove "A" text
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2014, 10:46 PM
  4. Remove Quotations Around Text File
    By ryanb4614 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-03-2013, 08:28 AM
  5. [SOLVED] How to correctly write "Value of cell E16" while having the quotations around it.
    By behnam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2013, 08:07 AM
  6. Auto generated Excel file
    By charleschia1986 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2013, 09:21 PM
  7. read in Vlookup an argument that has quotations(")
    By carlosgdlf in forum Excel General
    Replies: 1
    Last Post: 08-02-2005, 01:05 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