I'm trying to extract everything after the L or R (at the end) of the cell below into another cell. | ||||||||
<tbody> </tbody><colgroup><col></colgroup> |
<tbody>
</tbody><colgroup><col></colgroup>
I'm trying to extract everything after the L or R (at the end) of the cell below into another cell. | ||||||||
<tbody> </tbody><colgroup><col></colgroup> |
Sub testedmacro()
lastrow = Range("A1").End(xlDown).Row
For I = 2 To lastrow
If InStr(1, Cells(I, "D"), "L") > 0 Or InStr(1, Cells(I, "D"), "R") > 0 Then
a = InStrRev(Cells(I, "D"), "L", -1)
b = InStrRev(Cells(I, "D"), "R", -1)
If a > b Then
Cells(I, "E") = Right(Cells(I, "D"), Len(Cells(I, "D")) - a + 1)
ElseIf a < b Then
Cells(I, "E") = Right(Cells(I, "D"), Len(Cells(I, "D")) - b + 1)
Else
Exit Sub
End If
End If
Next I
End Sub
* | A | B |
1 | GL 480+32.2L32 | L32 |
2 | GL 489+01.3L32,1 | L32,1 |
3 | GL 2+00R32 | R32 |
4 | GL 3+00R32,545 | R32,545 |
5 | GL 3+00R32222,5 | R32222,5 |
Welcome to the MrExcel board!you can try
=IFERROR(RIGHT(A2,LEN(A2)-FIND("L",A2,4)+1),RIGHT(A2,LEN(A2)-FIND("R",A2,4)+1))
given all your text in column D starts from A1
Welcome to the MrExcel board!
If that idea works, and it very well might given the samples quoted, then this shorter version should also.
=MID(D2,FIND("R",SUBSTITUTE(D2,"L","R"),3),LEN(D2))