+ Reply to Thread
Results 1 to 12 of 12

text parsing

  1. #1
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    text parsing

    Hi there

    One of my line of code is as

    Please Login or Register  to view this content.
    where Address is the string pulled from another function.

    The string looks as follows

    "Q1 Zone - London"

    I want to parse the above string so that only Q1 Zone is pulled to my above line of code

    please advice
    Last edited by captedgar; 01-22-2010 at 09:23 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: text parsing

    Hello captedgar,

    The answer will depending on whether the hyphen is always present before the city name and what type of solution you are looking for: formulaic or VBA.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: text parsing

    Protecting against aan Address that doesn't have an "-", then
    Please Login or Register  to view this content.
    Use ShortAddress rather than address in the assignment statement

  4. #4
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    Re: text parsing

    Hi Blane

    I get a compiler error with expected array message.

    Hi Leith

    Yes, the hyphen will always be there and also i'm looking for VBA code preferably if its ok. Also Address is not equal to property of the object but a name of variable which is of type string. i'll change it below to avoid me confusing you

    So, in theory, when my following code gets executed

    Please Login or Register  to view this content.
    The TargetName variable pulls out different string variable depending on what are the contents of the row cell. I have about 15 cells each with different names on a row like

    Q1 Zone - London
    Q2 Zone - Paris
    Q3 Zone - Rome
    .
    .
    .
    Q14 Zone - Tokyo

    So when my above line of code gets called, i get the any of the above contents of the cell captured as row information and gets added to my email generator which is another function not to worry in this i guess.

    So instead of Q1 Zone - London, i want Q1 Zone only to be read and add to email generator





    Quote Originally Posted by blane245 View Post
    Protecting against aan Address that doesn't have an "-", then
    Please Login or Register  to view this content.
    Use ShortAddress rather than address in the assignment statement

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: text parsing

    Hello captedgar,

    You can isolate it this way...
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    Re: text parsing

    Hi Leith

    Thank you so much as it worked like a treat
    One last question on the same issue though

    On your code below

    Please Login or Register  to view this content.
    The highlighted line of code i.e. Range("F" + strCurrentRow).Value3 pulls contents from some other range of cells and adds them to the subject line

    Some of the contents of the Cells are like as follows

    PetrolPrice - Rate
    DieselPrice - Rate
    NetProfit - Value
    GrossProfit - Value
    TotalDeficit - AbovePar
    NetDeficit - AbovePar

    I want to exclude - Rate, - Value and - Above Par and just add only PetrolPrice, DieselPrice, NetProfit, GrossProfit, TotalDeficit and NetDeficit to the subject line

    Is this possible Leith?

    regards

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: text parsing

    Hello captedgar,

    This should do it...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    Re: text parsing

    Hi Leith

    only some of the contents has the following
    PetrolPrice - Rate
    DieselPrice - Rate
    NetProfit - Value
    GrossProfit - Value
    TotalDeficit - AbovePar
    NetDeficit - AbovePar

    There are other rows as well which has contents like PerCapita, AnnualTax, FiscalBudget etc.
    So the whole list of cell contents are as follows

    FiscalBudget
    PetrolPrice - Rate
    DieselPrice - Rate
    PerCapita
    NetProfit - Value
    GrossProfit - Value
    TotalDeficit - AbovePar
    NetDeficit - AbovePar
    AnnualTax

    what I want to know is can use trim and/or use exclude function(if it exists) so that contents of the cell before hyphen or if hyphen doesn't exist then the entire contents get captured to subject line

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: text parsing

    Hello captedgar,

    In my previous post, the variable ShortName2 will either be the entire text or if a hyphen is found, only the text to the left of the hyphen will be used. The following lines of code perform that function.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    Re: text parsing

    Thanks Leith

    This raises one last question i guess on the same topic

    How do i extract the text from the right side in the below list( which is actually the same as the one above)

    PetrolPrice - Rate
    DieselPrice - Rate
    NetProfit - Value
    GrossProfit - Value
    TotalDeficit - AbovePar
    NetDeficit - AbovePar


    So if i want to extract only Rate, Value, AbovePar?

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: text parsing

    Hello captedgar,

    To extract the data form the right of the hyphen, we use InStr again to find the hyphen, but now we take only the data to the right of it using the Right function.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-12-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    76

    Re: text parsing

    Thanks a lot Leith

    You have been exceptional patient and helpful in resolving. Thanks to your advice, i have the accurate solution to my problem

    regards


    Quote Originally Posted by Leith Ross View Post
    Hello captedgar,

    In my previous post, the variable ShortName2 will either be the entire text or if a hyphen is found, only the text to the left of the hyphen will be used. The following lines of code perform that function.
    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