1

I'm hoping someone can help me with an Excel formula to extract two characters after specific text in a string.

Specifically, the cell contains the following text

Every 2 Hours Power:1 Sail:0 SWC:3 BCR:0 CJC:0 CU:0 CSC:0

Note that all cells are slightly different so I can't just use the text to columns delimiter. I need the formula to return the two characters after the specific text "Power:". From the example above, I want the cell to read "1" after the text "Power:".

I've tried various combinations of Right, Left, Len, Search, and am not having success. Thanks in advance!

3
  • 1
    Assuming that text is in A1: =MID(A1,SEARCH("Power:",A1)+6,2) Commented Dec 28, 2023 at 23:00
  • And add “*1” to @Rory answer so it becomes a number instead of text, could also use value() Commented Dec 28, 2023 at 23:02
  • Thank you Rory and Solar Mike! This worked to get the numbers when there was accidentally a space between the : and the #. I then also used Mayukh's solution below to extract when there was no space. Thank you!! Commented Dec 30, 2023 at 15:41

2 Answers 2

1

Assuming there is no Excel Constraints as per the tags posted then one could use the following formula, which uses TEXTAFTER() & TEXTBEFORE()

enter image description here


=--TEXTBEFORE(TEXTAFTER(A1,"Power:")," ")

Or, Spill all at once,

=--TEXTBEFORE(TEXTAFTER(A1:A4,"Power:")," ")

Or, with TEXTSPLIT() & TEXTAFTER()

=--TEXTSPLIT(TEXTAFTER(A1:A4,"Power:")," ")

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Mayukh! This works perfectly. I used your first solution here. Happy New Years
1

If you are on Microsoft-365 then go with TEXTSPLIT().

=--TAKE(TEXTSPLIT(TEXTAFTER(A1,"Power:"),," "),1)

For other versions, I would suggest to use FILTERXML().

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.