up vote 0 down vote favorite
share [g+] share [fb]

I have a string in a cell:

ABCDxxxxxEFGH

ABCD and EFGH are constant, xxxxx is of variable length.

I want to write an excel formula to extract xxxxx.

link|improve this question
1  
This question will probably get migrated to superuser.com If you want to retain ownership of this question, you should have an account on superuser.com , and associate your accounts stackoverflow.com/users/104459?tab=accounts – Brad Gilbert Sep 21 '09 at 21:21
1  
You'll also get 100 point reputation bump, for associating your accounts. ( since you have more than 200 points ) – Brad Gilbert Sep 21 '09 at 21:23
feedback

migrated from stackoverflow.com Sep 22 '09 at 2:44

This question came from our site for professional and enthusiast programmers.

2 Answers

Assuming it is in Cell A1

=MID(A1,5,LEN(A1)-8)

If you wanted to check that the cell is correctly formed you could do:

=IF(LEN(A1)>8,IF(AND(LEFT(A1,4)="ABCD",RIGHT(A1,4)="EFGH"),MID(A1,5,LEN(A1)-8),NA()),NA())
link|improve this answer
+1 for the format check – Tracy Probst Oct 7 '09 at 16:09
feedback

If you just want to brute force it (assuming ABCD and EFGH aren't within xxxxx then the following approach should work, although I would recommend you come up with a better method.

myvariable = split(split(cell, "ABCD")(1), "EFGH")(0)

Please excuse if my syntax is slightly off, it's been a while since I've been in vbscript

link|improve this answer
feedback

Your Answer

 
or
required, but never shown