If Cell Starts with Text String… Formula

后端 未结 3 1579
悲哀的现实
悲哀的现实 2021-02-12 12:05

I have formula that checks if the cell starts with text \"A\" returns Pick up \"B\" for Collect and C for Prepaid.

But it doesn\'t seems to be working properly

B

3条回答
  •  被撕碎了的回忆
    2021-02-12 12:45

    I know this is a really old post, but I found it in searching for a solution to the same problem. I don't want a nested if-statement, and Switch is apparently newer than the version of Excel I'm using. I figured out what was going wrong with my code, so I figured I'd share here in case it helps someone else.

    I remembered that VLOOKUP requires the source table to be sorted alphabetically/numerically for it to work. I was initially trying to do this...

    =LOOKUP(LOWER(LEFT($T$3, 1)),  {"s","l","m"}, {-1,1,0})
    

    and it started working when I did this...

    =LOOKUP(LOWER(LEFT($T$3, 1)),  {"l","m","s"}, {1,0,-1})
    

    I was initially thinking the last value might turn out to be a default, so I wanted the zero at the last place. That doesn't seem to be the behavior anyway, so I just put the possible matches in order, and it worked.

    Edit: As a final note, I see that the example in the original post has letters in alphabetical order, but I imagine the real use case might have been different if the error was happening and the letters A, B, and C were just examples.

提交回复
热议问题