Every day we get an Excel file which contains a database dump. Most of the file is being sorted in a VBA script that I made but I have one remaining problem that I'm unable to resolve. In one of the columns (A) I sometimes have 2 strings, I only like to keep one of those. The string I'd like to keep looks like "M1234 5678". The digits do change... The column sometimes has other text before or after the M1234 5678. I'd like to remove all that text so I only keep the needed string.
I already tried to use a search function trying to tackle the problem using a trim function and searching for a string that looked like "M#### ####". Had no luck going down this road. I have to admit that It has been 2 weeks ago that I have been jiggling with the code below that it might be messed up for the thing I tried to solve at that point.
Sub TrimText()
Dim FinalValue As String
Dim lastStop As Long
With Sheets("Blad2")
lastStop = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastStop
FinalValue = Trim(Cells(i, 1).Value)
If InStr(FinalValue, "ALQ") > 0 Then
Cells(i, 1).Value = Left(FinalValue, InStr(FinalValue, "M*"))
End If
Next
End With
End Sub
I hope to delete any text on the left or right of the M#### #### string.
Thanks for the help.