-1

So I have this string in Excel: MS15-077[3077657]

and I just want to take the first part, MS15-077 to use to compare against other strings. Is there a way to just take the first 8 characters of the cell contents and set that as a variable?

Thanks!

3
  • Mid(s,1,8) should work Commented Jul 28, 2015 at 20:54
  • 2
    Yes - use Left$(Range("A1").Value, 8) in VBA or =LEFT(A1,8) as a formula. Commented Jul 28, 2015 at 20:55
  • possible duplicate of How to get a particular part of a String Commented Jul 28, 2015 at 22:16

1 Answer 1

0

You are looking for Mid:

If s = "MS15-077[3077657]"

Then Mid(s,1,8) = "MS15-077"

Or, as Rory pointed out, Left works as well and is specifically tailored for extracting substrings which appear on the left of the original string.

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

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.