By using t2do.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

T2Do.com

 


VBA Code to remove text from a string

Function RemoveText(pText, pStart, pEnd)
' don't change the passed values
lEnd = pEnd
lStart = pStart
sText = pText
If lEnd > lStart Then
    RemoveText = sText
    Exit Function
End If

If lStart < 1 Then
    lStart = 1
End If

If lEnd > Len(sText) Then
    lEnd = Len(sText)
End If



For i = 1 To Len(sText)
    If i >= lStart And i <= lEnd Then
        'skip it
    Else
        sNew = sNew & Mid(sText, i, 1)
    End If
    
Next
RemoveText = sNew
End Function