Home » excel » parsing – Excel parse cell value

parsing – Excel parse cell value

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have placed the following in cell A1:

"a lot of text marker: xxx some more text"

I would like to copy the xxx value into cell A2.

Any suggestions on how this could be done?

Thanks

How to&Answers:
=MID(A1, FIND("marker:",A1) + LEN("marker:"), 4)

I am assuming that the xxx (per your example) is 3 characters long and a space is present between “marker:” and “xxx”.

Answer:

Just my two cents. Find() is case sensitive so if the text in A1 is

“a lot of text Marker: xxx some more text”

Then Find will give you an error.

You can use Search() in lieu of FIND()

=MID(A1, SEARCH(“marker: “,A1) + LEN(“marker: “), 3)

Also depending upon your regional settings you might have to use “;” instead of “,”

Answer:

If you wanted a VBA solution, this worked for me using your sample input:

Function GetValue(rng As Excel.Range) As String
  Dim tempValue As String
  Dim arrValues() As String
  ' get value from source range
  tempValue = rng.value
  ' split by ":" character
  arrValues = Split(tempValue, ":")
  ' split by spaces and take the second array element
  ' because there is a space between ":" and "xxx"
  GetXXXValue = Trim$(Split(arrValues(1), " ")(1))
End Function

To use, put this code into the sheet module (see Where do I paste the code that I want to use in my workbook for placement assistance) and then put the following into cell A2:

=GetValue(A1)