Hello all,
I have a small Vba macro, that doesn't seem to work, because I am very new to vba and can't spot the likely simple error, any help would be much appreciated,
I am looking to enter a character into an input box and a range and then delete all text after and including the character/work in the input box.
Thanks in advance to anyone who wants to help
cheers
Sub RemovetextAfterCharacter()
'REMOVE ALL TEXT AFTER Character defined by Input box
'1st Criteria
Dim WorkRng As Range
Dim arr As Variant
Dim CharList As String
Dim Crit1 As String
On Error Resume Next
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", WorkRng.Address, Type:=8)
arr = WorkRng.Value
Crit1 = Application.InputBox("Input the character that you want to delete all text after from", "CHARACTER", Type:=8)
For Each c In WorkRng
If InStr(c.Value, Crit1) > 0 Then
c.Value = Left(c.Value, InStr(c.Value, Crit1) + Len(Crit1))
End If
Next c
End Sub
Bookmarks