regexexcelreplace

How to find and replace with regex in excel


I have an excel file with 1 column and multiple rows.

The rows contain various text, here's an example:

texts are home
texts are whatever
dafds
dgretwer
werweerqwr
texts are 21412
texts are 346345
texts are rwefdg
terfesfasd
rwerw

I want to replace "texts are *" where * is anything after "texts are" with a specific word, for example "texts are replaced". How can I do that in Excel?


Solution

  • As an alternative to Regex, running:

    Sub Replacer()
       Dim N As Long, i As Long
       N = Cells(Rows.Count, "A").End(xlUp).Row
    
       For i = 1 To N
          If Left(Cells(i, "A").Value, 9) = "texts are" Then
             Cells(i, "A").Value = "texts are replaced"
          End If
       Next i
    End Sub
    

    will produce:

    enter image description here