+ Reply to Thread
Results 1 to 5 of 5

Formula Question involving replacement.

  1. #1
    Registered User
    Join Date
    02-20-2009
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    2

    Formula Question involving replacement.

    Hi,

    I have a particular problem that i wouldn't think would be too difficult but is escaping me for some reason.

    Here's what i'm trying to do.

    I have several walking routes that are labeled A through H

    Each walking route has a different distance. .18 miles, 1.45 miles, etc...

    What i would like to do is be able to enter what routes are walked in a day and have it display the milage in a total cell.

    Example

    A person walked routes A twice, B and C once today.
    They walked a total of 5.64 miles.

    _______ __Total____
    | ABAC | 5.64 |
    -------- ------------


    What might the formula be?

    Thanks for the help, let me know if i need to provide further information.
    Last edited by steve meier; 02-24-2009 at 02:41 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formula Question involving replacement.

    This formula will tell you how many time "A" appears in cell A1.

    =LEN(A1)-LEN(SUBSTITUTE(A1,"A",""))

    Now you can use that answer to multiply off a table or a set of values

    =(LEN(A1)-LEN(SUBSTITUTE(A1,"A","")))*0.18

    Now you can string several of those together, I suppose.

    =((LEN(A1)-LEN(SUBSTITUTE(A1,"A","")))*0.18)+((LEN(A1)-LEN(SUBSTITUTE(A1,"B","")))*1.45)

    ...etc
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Formula Question involving replacement.

    An extension of JB's post.

    If we assume that A1:B9 holds the following:

    Please Login or Register  to view this content.
    Then we can have say the following A11:C13 (row 11 = headers)

    Please Login or Register  to view this content.
    Where the formula in C12 is:

    Please Login or Register  to view this content.
    The above formula can be copied down... as you alter the string of routes walked in column B so the miles in column C will recalculate... note it assumes each route is to be denoted by a singular character - if that changed (eg route "AA" so the approach would need to be altered)
    Last edited by DonkeyOte; 02-21-2009 at 05:48 AM.

  4. #4
    Registered User
    Join Date
    02-20-2009
    Location
    Washington
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Formula Question involving replacement.

    Thanks guys!

    That worked perfectly. I appreciate your time and knowledge.

  5. #5
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    That's too good a solution..!

    Hey DonkeyOte,

    You are truly amazing man, genius..I was actually having a similar requirement and this solution just fell in place at the right time..
    Simple compact yet robust...
    I needed to tag the prices for various Models assembled with various parts each having a cost to get the final cost..
    I think I can do some modification based on your code...

    JB's code was good as well to set the foundation ...

    Amazing...!

+ 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