0

I have an excel export with a column containing staff previous training sessions in a string. Example: First Name|Last Name|Training title|January 2018 to February 2018

Due to non obligatory form fields from which data was collected, many strings have no end month value, like this January 2018 to I'm trying to find a formula to find all strings ending with to (hence followed by nothing else) and delete this orphaned part of the string so it will look like January 2018.

Find and replace is useless as it also replaces the value when there's an end month/year. Substitute seems like a good way to go but I've failed trying to find the proper structure to the formula.

2 Answers2

3

Test whether it ends in to with right, and if so then use left to omit it:

=IF(RIGHT(A1,2) = "to",LEFT(A1,LEN(A1)-2),A1)
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
  • With some adaptations for my french version of Excel this worked flawlessly. Thank you Scott. In case a fellow baguette comes around here with the same issue: `=SI(DROITE(A1;2)="to";GAUCHE(A1;NBCAR(A1)-2);A1)` – InspectorG34 Feb 04 '19 at 17:48
0

This is with VBA. Dont forget to check for extra spaces at the end. if there are any use TRIM.

Option Explicit

Sub Remove()

    Dim Lastrow As Long, i As Long

    'Change Sheet if needed
    With ThisWorkbook.Worksheets("Sheet1")

        Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = 1 To Lastrow

            If Right(.Range("A" & i).Value, 2) = "to" Then
                .Range("A" & i).Value = Left(.Range("A" & i).Value, Len(.Range("A" & i).Value) - 3)
            End If
        Next i


    End With

End Sub
Error 1004
  • 7,877
  • 3
  • 23
  • 46