+ Reply to Thread
Results 1 to 31 of 31

Google Sheets - Split text by multiple delimiters

  1. #1
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Question Google Sheets - Split text by multiple delimiters

    Hi,

    I am trying to split text by multiple delimiters ; and CHAR(10) in Google Sheets with the below formula.

    =SPLIT(F2,{";",CHAR(10)},1,1)

    It only is splitting for the first delimiter listed in the formula, so in the above formula it is only splitting by the ";". If I move the CHAR(10) to the be the first one, it only splits by that.

    What I am doing wrong here?

    Thanks

  2. #2
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,419

    Re: Google Sheets - Split text by multiple delimiters

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

  3. #3
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by HansDouwe View Post
    Please try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    That works great, thank you!

    Would it be possible to add a character to each piece of split text within the same formula? I'd like to add an apostrophe to each bit of split text "'''.

    Thanks

  4. #4
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,419

    Re: Google Sheets - Split text by multiple delimiters

    Thanks for your feedback and rep .

    This formula add an apostrophe to each bit of split text:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by HansDouwe View Post
    Thanks for your feedback and rep .

    This formula add an apostrophe to each bit of split text:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    It only seems to work for the first bit of text before the first delimiter and then doesn't split the rest of the text.

    It also adds it so it is visible. I am using the apostrophe so Google Sheets doesn't try and format certain dates and convert them to random text. When I add the apostrophe before a date, it prevents this.

    I guess that isn't possible, thanks anyway!

  6. #6
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: Google Sheets - Split text by multiple delimiters

    I guess you need to add "ARRAYFORMULA" to the formula given by HansDouwe ;


    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by Haluk View Post
    I guess you need to add "ARRAYFORMULA" to the formula given by HansDouwe ;


    Please Login or Register  to view this content.
    Thanks, that works but is still showing the apostrophe rather than it being a hidden apostrophe like when I add it manually in front of text.

  8. #8
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,419

    Re: Google Sheets - Split text by multiple delimiters

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

  9. #9
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Thanks, but it produces the same result.

    Google Sheets must make it so it has to be done manually to be a hidden apostrophe?

  10. #10
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: Google Sheets - Split text by multiple delimiters

    I guess, you need a NULL character..... so, this will help you;

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by Haluk View Post
    I guess, you need a NULL character..... so, this will help you;

    Please Login or Register  to view this content.
    Unfortunately I think it is only an apostrophe that works to stop Google Sheets converting dates into random text. But it appears it must be added manually to the original text :/ to make it an invisible apostrophe :/

  12. #12
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: Google Sheets - Split text by multiple delimiters

    The last alternative works as desired on my end.

    If it's not the case for you, give a link to your sheet and let others to see what's going on...

  13. #13
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Sure, please see https://docs.google.com/spreadsheets...it?usp=sharing

    If you see where the date gets split into column J, it gets converted.

    So "02/01/2023" is becoming "44958".

  14. #14
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: Google Sheets - Split text by multiple delimiters

    May be this;

    Please Login or Register  to view this content.

  15. #15
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Google Sheets - Split text by multiple delimiters

    So "02/01/2023" is becoming "44958"
    Why is this a problem? 44958 is the serial number that corresponds to 1 Feb 2023 (and you should be able to see that if you format the cell with some kind of date format). The only problem I see with this output is if the date was intended to be 2 Jan 2023, in which case you need to check your google sheets settings to see what date convention (MDY or DMY or other) that it is using when it interprets text strings as dates.

    Edit to add: If there is a question about locale (these should be read as DMY dates, where the current version is interpreting as MDY dates), this essay has a good discussion of how Google Sheets (and other spreadsheets) store dates and times, along with a discussion of how to change locale settings in Sheets: https://www.ablebits.com/office-addi...e-date-format/
    Last edited by MrShorty; 01-07-2023 at 02:11 PM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  16. #16
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Google Sheets - Split text by multiple delimiters

    Another note. I don't know if my Google sheets is different (I doubt it), but I interpret the "delimiter" argument differently. Rather than a parametric array, I see it as a text string. I used =SPLIT(A3,";"&CHAR(10),1,1), and that seems to work just fine without the more complicated SUBSTITUTES() that you are currently using. Note that the "delimiter" argument is a single argument containing all of the desired characters (in this case, it contains a semicolon and a carriage return character).

    I don't know if that helps or confuses. I'm hoping it helps.

  17. #17
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by Haluk View Post
    May be this;

    Please Login or Register  to view this content.
    This kind of works, but only when the date is entered with a / and it does just change the format of the date to use a - . I need to keep it as it was originally entered.

    This is user input data so sometimes users enter a dates in various formats unfortunately there is nothing I can do about this :/

  18. #18
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by MrShorty View Post
    Why is this a problem? 44958 is the serial number that corresponds to 1 Feb 2023 (and you should be able to see that if you format the cell with some kind of date format). The only problem I see with this output is if the date was intended to be 2 Jan 2023, in which case you need to check your google sheets settings to see what date convention (MDY or DMY or other) that it is using when it interprets text strings as dates.

    Edit to add: If there is a question about locale (these should be read as DMY dates, where the current version is interpreting as MDY dates), this essay has a good discussion of how Google Sheets (and other spreadsheets) store dates and times, along with a discussion of how to change locale settings in Sheets: https://www.ablebits.com/office-addi...e-date-format/
    It is a problem because I need the date to be exactly as the user entered it. I also work with international dates, so it just needs to be treated as plain text without being converting to the serial number.

    Quote Originally Posted by MrShorty View Post
    Another note. I don't know if my Google sheets is different (I doubt it), but I interpret the "delimiter" argument differently. Rather than a parametric array, I see it as a text string. I used =SPLIT(A3,";"&CHAR(10),1,1), and that seems to work just fine without the more complicated SUBSTITUTES() that you are currently using. Note that the "delimiter" argument is a single argument containing all of the desired characters (in this case, it contains a semicolon and a carriage return character).

    I don't know if that helps or confuses. I'm hoping it helps.
    Thanks, that does also work. I guess I using a comma instead of an & in my original formula which was why it wasn't working!

  19. #19
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Google Sheets - Split text by multiple delimiters

    IME, storing dates and numbers as text in a spreadsheet generally creates more problems than it solves. Therefore, I would say that the best spreadsheet programming practice is to allow the spreadsheet to convert the text to a number while giving the sheet the correct locale information so that it can read the text dates correctly. There are exceptions to every rule, however. Before exploring this, I think I would want to understand what your project is doing with these dates that would necessitate storing dates as text. Most of the time, it seems we find that it is easy enough to store dates as numbers and still accomplish the programming goals of the spreadsheet.

  20. #20
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    The text/date and other information is printed onto custom products, so it needs to be displayed exactly how it was entered, as that is how they have requested it to be. For this reason, it can't be altered at all.

  21. #21
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Google Sheets - Split text by multiple delimiters

    If you make sure that Sheets can correctly read the date text and apply an appropriate number format (Sheets automatically applied the appropriate number format in my test), then it should display exactly as entered. I am not as experienced with Sheets, so I don't know exactly what one would need to do to prevent sheets from converting the date text to a number. If the main concern is one of "printed appearance," I see no problem with letting Sheets convert to a number and apply an appropriate number format to the field (if Sheets does not automatically apply the number format).

  22. #22
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    I can't make sure that G Sheets can read it, as like I said, I have no control over how the user enters the date. It can be many different formats. Some G Sheets understands, some it doesn't. Also, like I have said, it needs to be exactly how it was entered, not converted to a different format.

    The only way I know to prevent it is to add an apostrophe before the original date text which is what we were trying to accomplish earlier on in the thread.

  23. #23
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Google Sheets - Split text by multiple delimiters

    Try including the quote in the substitution and prefixing the cell with a quote in case the date is at the start:

    =ARRAYFORMULA(SPLIT(substitute(substitute("'"&F2,CHAR(10),";"),";",";'"),";",1,1)&"")
    Rory

  24. #24
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by rorya View Post
    Try including the quote in the substitution and prefixing the cell with a quote in case the date is at the start:

    =ARRAYFORMULA(SPLIT(substitute(substitute("'"&F2,CHAR(10),";"),";",";'"),";",1,1)&"")
    Amazing, that worked, thanks so much!

  25. #25
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by rorya View Post
    Try including the quote in the substitution and prefixing the cell with a quote in case the date is at the start:

    =ARRAYFORMULA(SPLIT(substitute(substitute("'"&F2,CHAR(10),";"),";",";'"),";",1,1)&"")
    Is it possible to add the TRIM function to this formula? So that any spaces are removed in the text that is split?

  26. #26
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Google Sheets - Split text by multiple delimiters

    Yes - this should work:

    =ARRAYFORMULA(TRIM(SPLIT(substitute(substitute("'"&F2,CHAR(10),";"),";",";'"),";",1,1)&""))

  27. #27
    Registered User
    Join Date
    11-11-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Google Sheets - Split text by multiple delimiters

    Quote Originally Posted by rorya View Post
    Yes - this should work:

    =ARRAYFORMULA(TRIM(SPLIT(substitute(substitute("'"&F2,CHAR(10),";"),";",";'"),";",1,1)&""))
    Amazing, thanks!

    I wish they had a buy beer/coffee button on here!

  28. #28
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Google Sheets - Split text by multiple delimiters

    Then you'd just have drunk, overstimulated helpers.

  29. #29
    Registered User
    Join Date
    02-04-2021
    Location
    Csatar
    MS-Off Ver
    MS Office 2019
    Posts
    22

    Re: Google Sheets - Split text by multiple delimiters

    How to set multiple delimiters? like? ";," ?

  30. #30
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Google Sheets - Split text by multiple delimiters

    See post #16 in this thread.

  31. #31
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Google Sheets - Split text by multiple delimiters

    If it will help, here is Google's help file for the SPLIT() function, including a description of how to use the delimiter argument in conjunction with the split_by_each argument to control what character(s) is (are) used as delimiters: https://support.google.com/docs/answer/3094136

+ 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. Split text into columns with multiple delimiters
    By fady_23 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-26-2022, 04:40 PM
  2. Macro to split text string based on its various structure/delimiters
    By Velehrad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2020, 11:24 PM
  3. Macro to split large range of text with multiple delimiters.
    By QUAKE2K in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 11-06-2019, 10:35 AM
  4. Split Text Inconsistent Data and Delimiters
    By kreiner2006 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-25-2019, 08:45 PM
  5. Split data by delimiters but by formula (not Text to Columns)
    By STUARTXL in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-19-2016, 05:44 AM
  6. Replies: 2
    Last Post: 04-09-2014, 11:48 AM
  7. Split text into array using multiple delimiters
    By TKFRMjarvis in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-26-2014, 03:07 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