Excel VBA - delete string content up to *word*
Simple example of dropping all text before value in string.
Sub Foo() Dim strOrig As String Dim strReplace As String strOrig = "The Quick brown fox jumped over the lazy dogs" strReplace = "jumped" MsgBox (DropTextBefore(strOrig, strReplace))End SubPublic Function DropTextBefore(strOrigin As String, strFind As String) Dim strOut As String Dim intFindPosition As Integer 'case insensitive search 'could made it so that case sensitivity is a parameter but this gets the idea across. If strOrigin <> "" And strFind <> "" Then intFindPosition = InStr(UCase(strOrigin), UCase(strFind)) strOut = Right(strOrigin, Len(strOrigin) - (intFindPosition + Len(strFind) - 1)) Else strOut = "Error Empty Parameter in function call was encountered." End If DropTextBefore = strOutEnd Function
If the word is fixed, like "They" in the above example, you can simply do
- CTRL + H (Replace)
- *They (your word with a star)
in the Find box. The star * is a wildcard character which can be called as - of anything before or after (if added at end) the word.
Cautious: Take care when you have duplicate words in the same cell.