Search code examples
stringexcelcellvba

Excel VBA-delete string and following line within a cell


I need to delete certain strings (e.g. "SUBJECT:", there is a line break after this string), and the entire following line, to and including the next line break, from within multiple cells in Excel.

How can I write a macro for this?

I am guessing it would be

Cells.Replace What:="Subject:" & Chr(10) & "[ANY TEXT]" & Chr(10), Replacement:="", Lookat:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False


Solution

  • This worked in my case!

    Selection.Replace What:="Subject:" & Chr(13) & "*" & Chr(13) & Chr(10), Replacement:="", Lookat:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False