+ Reply to Thread
Results 1 to 9 of 9

Dim String, and divide/split into parts

  1. #1
    Registered User
    Join Date
    05-09-2012
    Location
    Calgary,Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Dim String, and divide/split into parts

    Hello experts,

    I have a string, and I need to split it into parts, and each part will represent different things, the parts will be seperated by either "." or "_", for example:

    TOPOLOGY.WC.39.214S.138.DICKSON_DAM1

    How do I dim it as a string with 7 parts. Or dim it as a whole and split it into 7 parts, then define the parts like ID=part(3), NAME=part(1) etc...


    Thank you for your help in advance
    Hallet

  2. #2
    Registered User
    Join Date
    12-15-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Dim String, and divide/split into parts

    You can use something like this:


    Please Login or Register  to view this content.
    Just rename your "parts" to whatever you want.

    Good Luck!
    If I helped you today please rate me

  3. #3
    Registered User
    Join Date
    05-09-2012
    Location
    Calgary,Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Dim String, and divide/split into parts

    Thank you so mych lmvk99!
    Appreciate your help!

  4. #4
    Registered User
    Join Date
    05-09-2012
    Location
    Calgary,Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Dim String, and divide/split into parts

    Hello Experts,


    So I haven't actually tried the code yet, but I don't really understand the "a6" part.
    And I ran into a bit of a roadblock, more like a special case. So in the same string "TOPOLOGY.WC.39.214S.138.DICKSON_DAM1", there are 6 parts:
    part1:TOPOLOGY
    part2:WC
    part3:39
    part4:214S
    part5:138
    part6:DICKSON

    since I am using "." as a divider, everything works fine.
    However part 5 can be a decimal value, for example "TOPOLOGY.WE.30.62S.13.8.BRAZEAU_HYDRO2",
    In this case part 5 has the value "13.8", so it would have 7 parts instead of 6.
    I was thinking to counter this I can split it into 7 parts first, and check if part 7 is empty or not, but have no idea how to put that into code language as I am very new to VBA
    And also I need a way to trim whatever is after the underscore including the underscore, "_HYDRO2" is useless for example, so is "_DAM1"



    Thanks in advance
    Hallet

  5. #5
    Registered User
    Join Date
    12-15-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Dim String, and divide/split into parts

    The A6 just happened the be the cell reference where I dropped your string. Just change it to the cell reference of the actual string you want. I will step through in some more detail because you are new to VBA. If you want it to loop through many cells in a list and put the split out text into the columns next to it, you probably want to change it to something like this:


    Please Login or Register  to view this content.
    All you need to do is name your list of original values "list" and make sure the 7 columns next to it are clear.

    Good Luck!

  6. #6
    Registered User
    Join Date
    05-09-2012
    Location
    Calgary,Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Dim String, and divide/split into parts

    HI Imvk99,
    thank you so much for responding in such detail.
    Here's the actual file with the strings
    EMS_MODEL1.xlsx
    However the number of rows of data will vary, since this is only part of the actual file, so I probably will need a Do Until IsEmpty, and I just need to split the parts, and give each part a variable name.
    So would you please modify your code for me? =)


    Appreciate your help!

    Hallet

  7. #7
    Registered User
    Join Date
    12-15-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Dim String, and divide/split into parts

    I am not sure exactly what you mean exactly by:

    and I just need to split the parts, and give each part a variable name
    But if you want to make it so it picks up your range even if it gets longer, just use a dynamic range name for your range "list":

    =OFFSET(gen!$B$11,,,COUNT(gen!$G:$G),1)

  8. #8
    Registered User
    Join Date
    05-09-2012
    Location
    Calgary,Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Dim String, and divide/split into parts

    I think I got it now, sorry about the confusion, what I meant was I just want to give a name for each part like your very first post did, "part1, part2, etc..."

    Thanks so much

  9. #9
    Registered User
    Join Date
    12-15-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Dim String, and divide/split into parts

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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