Option Explicit
Private Sub Strip_PN()
Dim prefix As String
Dim suffix As String
Dim MyStr, Default
Dim rng As Range
Application.ScreenUpdating = False
MsgBox ("This Macro will Auto Delete the Customer Prefix and the following Suffixes: -LF, -MN, -M0*, and -C" & Chr(13) & Chr(13) & _
"Please enter any specific Prefixes and Suffixes you wish to delete into the next two input boxes.")
MyStr = Cells(2, 3)
Default = (Left(MyStr, 3))
prefix = UCase(Trim(InputBox("Enter Customer Prefix to Delete", "Prefix for Each Cell", Default)))
suffix = UCase(Trim(InputBox("Enter Optional Suffix to Delete" & Chr(13) & Chr(13) & "Leave blank if NO Optional Suffix needed!", "Suffix for Each Cell")))
Set rng = Range("A1", Cells(Rows.Count, 1).End(xlUp))
With rng
If Not IsEmpty(prefix) Then
If Not InStr(1, prefix, "-") > 0 Then
prefix = prefix & "-"
End If
.Replace What:=prefix, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End If
If Not IsEmpty(suffix) Then
If Not InStr(1, suffix, "-") > 0 Then
prefix = "-" & suffix
End If
.Replace What:=suffix, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End If
.Replace What:="-LF", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
.Replace What:="-MN", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
.Replace What:="-M0*", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
.Replace What:="-C", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
Application.ScreenUpdating = False
End Sub
Bookmarks