+ Reply to Thread
Results 1 to 4 of 4

Question - Substitution function is substitution its own values

  1. #1
    Registered User
    Join Date
    07-31-2018
    Location
    Florida, United States
    MS-Off Ver
    Office 10
    Posts
    1

    Question Question - Substitution function is substitution its own values

    Hello,

    I was trying to replace certain values with other values (e.g., 1 to 100, 2 to 80) and used the following syntax:

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B3,1,100), 2,80), 3,60), 4,40), 5,20), 6,0)

    However, for the value 3, it generated 00 as output instead of 60. It had changed 3 to 60, and then changed the 6 in 60 to a 0, which resulted in 00. Is there a way to prevent Excel from double substituting like this?

    Thank you.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,705

    Re: Question - Substitution function is substitution its own values

    Here's an alternative:

    =CHOOSE(B3,100,80,60,40,20,0)

    and another way:

    =100-(B3-1)*20

    both of which return numeric values.

    Hope this helps.

    Pete

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Question - Substitution function is substitution its own values

    If B3 only contains 1 of the numbers to be substituted then I would suggest using either of Pete's methods.

    If the digits / characters to be substituted are part of a longer string in B3, then you will need substitute to be able to change only part of it.

    The rule to follow with multiple substitutions like this is to order them so that you substitute x before you substitute with anything that contains x.

    So in your formula, you need to substitute 6 for 0 before substituting 3 for 60
    Likewise, 2 needs to be substituted before 5 is substituted by 20 to prevent 20 from becoming 800.

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B3,6,0), 2,80), 3,60), 4,40), 5,20), 1,100)

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,705

    Re: Question - Substitution function is substitution its own values

    I didn't point out explicitly, though I hinted at it in my final comment, that the SUBSTITUTE function returns text values, which is why you got 00 rather than just 0. If you want numbers rather than text values then you can multiply the whole of the nested SUBSTITUTE formula by 1, or add zero (i.e. add *1 or +0 at the end).

    If you DO want text values, then with my formulae you can add &"" to the end of the formulae.

    Hope this helps.

    Pete

+ 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. [SOLVED] Need help on substitution worksheet
    By Ereman82 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-13-2016, 10:39 AM
  2. Replace/substitution function
    By 1question in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-08-2016, 11:49 AM
  3. [SOLVED] substitution of Values
    By akbar in forum Excel General
    Replies: 7
    Last Post: 08-18-2012, 06:12 AM
  4. Substitution of values
    By macedo in forum Excel General
    Replies: 16
    Last Post: 05-13-2012, 08:47 PM
  5. If then substitution
    By knitterkuba in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-13-2010, 05:24 AM
  6. [SOLVED] substitution
    By Cossloffe in forum Excel General
    Replies: 1
    Last Post: 06-04-2006, 02:10 AM
  7. Substitution
    By Boenerge in forum Excel General
    Replies: 2
    Last Post: 05-23-2005, 08:06 AM

Tags for this Thread

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