+ Reply to Thread
Results 1 to 25 of 25

Problem separating a long string into four separate fields?

  1. #1
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Problem separating a long string into four separate fields?

    Hi

    I have a little training, from a course I did some time ago, with functions such as LEFT, MID, RIGHT, FIND, IF etc. Nesting I need some practice with but am sure I will get there.

    I have my first task in the real world and it is to separate a string into four separate fields (please see image at the bottom).

    An example of the string, one of several hundred of them, is COMP10000 Introduction to Computing 2015-16 2nd Semester.

    My challenge is to separate it into four fields:
    Course code: COMP10000
    Year: 2015-16
    Course title: Introduction to Computing
    Semester: 2nd Semester

    The first step to separate the course code was easy and I used the formula =LEFT(G2,FIND(" ",G2)-1) where the full string is in cell G2. I then fill down for several hundred records.

    I hope kind folk can hold my hand through the next three fields?

    YEAR
    The year is in the middle of the string but even if I used MID cannot use FIND to locate the space as there are a number of them?

    SEMESTER
    My first instinct is to use RIGHT and FIND but there are two spaces not one?
    Also in some cases there is a blank with the relevant semester or full year missing (where I would probably treat it as full year).

    COURSE TITLE
    Probably a combination of MID and FIND and another function?

    I would very much appreciate a steer on how best to approach these remaining 3 fields?

    Many thanks!

    capture20160613162709489.png
    Last edited by colgor; 06-13-2016 at 11:35 AM. Reason: To make the header clearer

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,830

    Re: Problem separating a long string into four separate fields?

    Please post a file (not image) with a representative sample of your strings.

    To upload a file click "Go Advanced" then scroll down to "Manage Attachments"

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem separating a long string into four separate fields?

    Hi,

    One way
    Year:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

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

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


    Usual caveat with all this string slicing stuff. The text strings must be consistent. e.g. the year must always be yyyy-yy not say yyyy-yyyy, or yyyy:yy
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    Thanks John. I've attached an Excel 2013 file with a little more sample data as requested. Though there are several hundred records in the real data I think the sample I have given should suffice, if not please let me know? Thanks again.

  5. #5
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    PS. Re. 'CHEM10111 Introductory Chemistry 2015-16 ', in row 3, there are records like that in the real dataset where there is missing information for the semester field. Only one example in my sample but it is not unique.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem separating a long string into four separate fields?

    ...did you try the formulae I gave you in post #3?

    Obviously change the G1 reference to G2 & N1 to N2 where necessary.

  7. #7
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    Richard, sorry I should have read all posts first, rather than work through one at a time. Lesson learnt and will test your formulas now and feedback very shortly. Thanks you! :-)

  8. #8
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Problem separating a long string into four separate fields?

    Enter formula in cell N2 and pull formula across and then down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v G H I J K L M N O P Q
    1 COURSE_NAME Course code Course Title Year Semester
    2 COMP10000 Introduction to Computing 2015-16 2nd Semester COMP10000 Introduction to Computing 2015-16 2nd Semester
    3 PHYS10100 Introduction to Physics 2015-16 Full Year PHYS10100 Introduction to Physics 2015-16 Full Year
    4 CHEM10111 Introductory Chemistry 2015-16 CHEM10111 Introductory Chemistry 2015-16
    5 GEOG10754 Introduction to Geography 2015-16 1st Semester GEOG10754 Introduction to Geography 2015-16 1st Semester
    6 MATH21192 Maths 2015-16 2nd Semester MATH21192 Maths 2015-16 2nd Semester
    7 HIST21202 History 2015-16 2nd Semester HIST21202 History 2015-16 2nd Semester
    8 SCIE21211 Science 2015-16 1st Semester SCIE21211 Science 2015-16 1st Semester
    9 LITE21221 Literature 2015-16 1st Semester LITE21221 Literature 2015-16 1st Semester
    10 LATI21232 Latin 2015-16 2nd Semester LATI21232 Latin 2015-16 2nd Semester
    11 INFO21242 IT 2015-16 2nd Semester INFO21242 IT 2015-16 2nd Semester
    12 COSC21252 Computer Science 2015-16 2nd Semester COSC21252 Computer Science 2015-16 2nd Semester
    13 PHED21261 Physical Education 2015-16 1st Semester PHED21261 Physical Education 2015-16 1st Semester
    14 DRAM21272 Drama 2015-16 2nd Semester DRAM21272 Drama 2015-16 2nd Semester
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,830

    Re: Problem separating a long string into four separate fields?

    Richard, they are working OK!!!

  10. #10
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    Year and Semester works a treat thank you Richard. Course title adds the course code at the beginning though, for example 'COMP10000 Introduction to Computing' only needs to be 'Introduction to Computing'. I expect it just needs a tweak. I will use the formulas to get the real job done then return when I can to work out exactly how the formulas were put together. You guys inspire me to learn not just ask! I note another reply below so will take a look too, I think there can often be more than one way to skin a cat.
    Last edited by colgor; 06-13-2016 at 02:40 PM.

  11. #11
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    That is very clever Alkey thank you, it works great. So way above my head that I might be tempted to use Richard's solution, once he comes back to me on tweaking the course title field. That way, I might get a way with bluffing my way and pretending to my boss that I actually did the code! :-) Seriously, I will test both now with the real data. I have a real heavy schedule coming up over summer but I will no doubt return to this thread (when no longer necessary simply for the task in hand) and ask questions, perhaps, once I've youtubed the functions that are new to me and tried to follow your formulas. I love the way Excel is so powerful and am keen to learn.

  12. #12
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    Thanks for starting the ball rolling John. Lots of really helpful folk on here including you, thanks again!

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,830

    Re: Problem separating a long string into four separate fields?

    With Richards's formula I did not get the course code added to the course title. Check the formula again.

  14. #14
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    SNAG!

    In both cases, Richard and Alkey, when transferring the code to several hundred records the long course titles sometimes get split and overwritten into the Year and Semester fields. It might be that I need to let you know the maximum length of the string or course titles? I have no problem sharing the actual data with one or both if that helps? There is no personal data but it belongs to the organisation I work for so would rather not publish it wider than that? Non Excel things now like getting fed and saying a few words to family so will login in later this evening or tomorrow now to look for your replies. Thanks again!!!

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,830

    Re: Problem separating a long string into four separate fields?

    Post a file with samples of the "snags" !!!!

  16. #16
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem separating a long string into four separate fields?

    Quote Originally Posted by colgor View Post
    Year and Semester works a treat thank you Richard. Course title adds the course code at the beginning though, for example 'COMP10000 Introduction to Computing' only needs to be 'Introduction to Computing'. I expect it just needs a tweak. I will use the formulas to get the real job done then return when I can to work out exactly how the formulas were put together. You guys inspire me to learn not just ask! I note another reply below so will take a look too, I think there can often be more than one way to skin a cat.
    Hi,

    I don't see that - see attached.

  17. #17
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem separating a long string into four separate fields?

    Quote Originally Posted by colgor View Post
    SNAG!
    ...There was a caveat in my post #3.

    Often we find with large data sets that what might work for a small subset does not with the whole population since there may be subtle differences which affect string slicing stuff.

    Stating the obvious I suppose, but can't the system which spews out the single string of data include field separator characters?

    If you have encountered snags then we'll need to see examples. Densitise the data if necessary but make sure it still 'snags' so that we have something to work with and correct

  18. #18
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    I noted your caveat Richard, thanks, but I hoped it would not be an issue as when skimming all seemed OK.

    Indeed, going back to the data provider in my organisation was my first thought, but I saw it as an opportunity to practice, learn more and apply some of my learning. If we hit a brick wall I will do certainly do that.

  19. #19
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    OK, Richard, I did it again and your course title formula worked so I must have typed or pasted it in wrong somehow the first time I tried it.

    I am attaching a small sample of real data where there are still problems though. I have taken many of the correct rows out so there appears to be more incorrect than there actually are. I hope it is enough to see where the problem might be?

    Thanks again!

  20. #20
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Problem separating a long string into four separate fields?

    Please see attached file with improved formula that should work fine with your data.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  21. #21
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem separating a long string into four separate fields?

    Quote Originally Posted by colgor View Post
    OK, Richard, I did it again and your course title formula worked so I must have typed or pasted it in wrong somehow the first time I tried it.

    I am attaching a small sample of real data where there are still problems though. I have taken many of the correct rows out so there appears to be more incorrect than there actually are. I hope it is enough to see where the problem might be?

    Thanks again!
    Variations
    O2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


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


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

  22. #22
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    Many thanks Alkey. Works almost perfectly with the real data. There are though just a few records that still don't work. It is where the string and particularly the course title are too long so spill into the other cells. The maximum characters of a course title including spaces appears to be 126 and the maximum string length including spaces appears to be 161. Can that help you to to polish it off?

    As an aside, this exercise has proved that the data analysis course I did has taught me what can be done but the complex formulae, unless I am working regularly with complex datasets, might be impractical for me to take time to learn as so much practice would be required? But once the real world problem is solved (nearly!) then I can still learn on YouTube about TRIM SUBSTITUTE SEARCH etc and help me get how you did it and what is possible in future, but perhaps only with the help of your good selves on this forum? It might be best to simply ask for some code as required as in this case though of course I will learn what is doable?
    Last edited by colgor; 06-15-2016 at 07:33 AM.

  23. #23
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    I'm afraid the new variations gave similar results Richard. Alkey has almost got me there as you will see from the other post. In the short term Alkey's approach should get the job done. However, if you are happy and have time, I'm still happy to get your alternative way to work. My second paragraph in post 22 applies equally to the work I have beendoing wiht you. Your codes are broken down and might be easier to follow when trying to work out how you did it? I might then step up and look at Alkey's one code solution?

  24. #24
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem separating a long string into four separate fields?

    Quote Originally Posted by colgor View Post
    I'm afraid the new variations gave similar results Richard.
    Was that with the test data you originally sent or new data which may have different formats?

    Clearly you have a working formula from Allkey which is great. Just for completion this is the workbook with the variation formulae in.

  25. #25
    Registered User
    Join Date
    12-08-2015
    Location
    UK
    MS-Off Ver
    2013 (sometimes 2010)
    Posts
    31

    Re: Problem separating a long string into four separate fields?

    Yes, thanks Richard, I tested it on real data. The email you just attached is skewed with data across the fields but no matter.
    Should AlKey tweak that last piece of code my real life problem should be solved. Thanks again to you both.

+ 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. Separating Lat and Long into Two cells
    By $J$L$G in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-27-2014, 06:33 PM
  2. [SOLVED] How to separate names in a long cell string
    By mondello in forum Excel General
    Replies: 5
    Last Post: 08-02-2012, 02:59 AM
  3. Separating an address string into separate parts using vba
    By adhbrown in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-30-2010, 04:08 PM
  4. Taking long list in one column and separating it
    By washoutinc in forum Excel General
    Replies: 6
    Last Post: 04-02-2009, 05:53 PM
  5. separating fields
    By Risa in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-01-2005, 03:30 AM
  6. Separating a string to two fields
    By asdf032 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-08-2005, 01:57 PM
  7. Help requested (quite long!)
    By Lee Davison in forum Excel General
    Replies: 7
    Last Post: 04-13-2005, 10:06 AM
  8. Separating Fields
    By pligger in forum Excel General
    Replies: 1
    Last Post: 03-22-2005, 05:25 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