I have lots of entries that have the form "+6+2", "+4+3", "+5+1".
Is there any way to extract the second half, so the "+2", "+3", "+1" - part
?
(Not all of the entries concerned are like that; somre simply read "+6",
"+3", "+2"; in that case the extraction should read "0")
Thanks in advance,
Gilbert
You could use a User Defined Function.
This assumes you have provided inclusive examples of the format of your
entries. If you have not, we will need to change re.Pattern.
pattern: Quotes | + | digit(s) | + | digit(s) | quotes | end-of-line
<alt-F11> opens the VB Editor.
Ensure your project is highlighted in the Project Explorer window, then
Insert/Module and paste the code below into the window that opens.
Insert/Module and paste the code below into the window that opens.
Use a formula =LastPlus(cell_ref) where cell_ref is the address of a cell
containing your string.
==================================
Option Explicit
Function LastPlus(str As String) As Variant
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "(\d)(\+\d+(?=""$))"
If re.test(str) = True Then
Set mc = re.Execute(str)
LastPlus = mc(0).submatches(1)
End If
End Function
=================================
--ron