+ Reply to Thread
Results 1 to 7 of 7

Truncating a text string based off of two unique criteria

  1. #1
    Registered User
    Join Date
    04-30-2013
    Location
    Arkansas
    MS-Off Ver
    Excel 2013
    Posts
    96

    Truncating a text string based off of two unique criteria

    Example: campaign=TEST&
    I need the query to return "campaign=Test"

    campaign=ExcelForum&
    I need the query to return "campaign=ExcelFOrum"

    I need everything left of the "&" , but there are multiple ampersands within the text string. I need a query that will locate "campaign=" then look for the first instance of an "&" after "campaign=", and then return everything prior to the "&".

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Truncating a text string based off of two unique criteria

    Assuming your string is in L8:
    =MID(L8,FIND("campaign=",L8),FIND("&",RIGHT(L8,LEN(L8)-FIND("campaign=",L8))))
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Registered User
    Join Date
    04-30-2013
    Location
    Arkansas
    MS-Off Ver
    Excel 2013
    Posts
    96

    Re: Truncating a text string based off of two unique criteria

    Would I replace L8 with the actual table and field name if I want to do this in a query in MS Access?

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Truncating a text string based off of two unique criteria

    I think Pauley thought this was an excel question, not an access question - that is an excel formula (and so did I actually, until I read your last post and then looked at the forum it was posted in)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Truncating a text string based off of two unique criteria

    Oh, yeah. Whoops.

    However, I believe it is very similar. FIND becomes InStr. You would create a calculated field and the L8 would be replaced with your original field name (ex. [OrigString]). Something like this:
    MID(L8,InStr([OrigString],"campaign="),InStr(RIGHT([OrigString],LEN([OrigString])-InStr([OrigString],"campaign=")),"&"))

  6. #6
    Forum Contributor
    Join Date
    05-08-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    102

    Re: Truncating a text string based off of two unique criteria

    I may be missing something from the way the question is worded, but I am assuming that I have a table in Access named Test with one field named ID. The table has various records such as "campaign=TEST&" and "campaign=Forum&".

    What I did was to build a custom function in VBA as follows:

    Please Login or Register  to view this content.
    Then I run the following SQL statement:

    Please Login or Register  to view this content.
    The results I get are as follows: "campaign=Test" and "campaign=Forum".
    Last edited by Dimitrov; 02-13-2014 at 09:47 PM.

  7. #7
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Truncating a text string based off of two unique criteria

    Dimitrov - the examples were simpler than the possibilities. The input string could have multiple &'s and other text both before and after "campaign=".

    AlphaSkidz - Just checked my solution in a query table. It worked other than I left one more L8 in the equation. This is what worked for me:
    MID([OrigString],InStr([OrigString],"campaign="),InStr(RIGHT([OrigString],LEN([OrigString])-InStr([OrigString],"campaign=")),"&"))

+ 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. Counting Unique text in column B based on a criteria from column a
    By clocmasta in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-18-2013, 06:40 PM
  2. Replies: 1
    Last Post: 04-08-2013, 07:07 PM
  3. Formula to count Unique text based on multiple criteria
    By OAMPS in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-14-2012, 10:48 AM
  4. Truncating a text string
    By bob in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-20-2005, 04:10 PM
  5. [SOLVED] Truncating a text string
    By gavin in forum Excel General
    Replies: 7
    Last Post: 05-10-2005, 08:06 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