Dinesh_Excel
Member
Hi Friend,
I am trying to find a text in a range say column "A" and replace the same with a different text in a separate row adjacent to that text.
I tried the below code but it has a blank on the first row and adding "Red" in place where there is blank.
Appreciate your help
![upload_2017-9-8_20-55-27.png upload_2017-9-8_20-55-27.png](https://chandoo.org/forum/data/attachments/45/45321-da934cc0e0c45d70b9aebc7ce7d98601.jpg)
I am trying to find a text in a range say column "A" and replace the same with a different text in a separate row adjacent to that text.
I tried the below code but it has a blank on the first row and adding "Red" in place where there is blank.
Appreciate your help
![upload_2017-9-8_20-55-27.png upload_2017-9-8_20-55-27.png](https://chandoo.org/forum/data/attachments/45/45321-da934cc0e0c45d70b9aebc7ce7d98601.jpg)
Option Explicit
Sub Replace_Text()
Dim last row As Long, rng As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
With Sheet1
.AutoFilterMode = False
Set rng = .Range("A2:A" & lastrow)
rng.AutoFilter field:=1, Criteria1:="Apple*"
rng.Offset(1, 5).SpecialCells(12).Value = "Red"
.Cells(lastrow + 1, 1) = ""
.AutoFilterMode = False
End With
Application.ScreenUpdating = True
Set rng = Nothing
End Sub