VBA Solution Find and Replace

sachavez

Active Member
Joined
May 22, 2009
Messages
469
If cell in column A contains x, and cell in column E contains y, change text in column E to abcd.

Example, if cell in Column A contains "LOSANGELE", and cell in column E is "IY", then change "IY" to "abcd".

Thanks in advance
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How about
Code:
Sub sachavez()
   Dim Cl As Range
   Dim St1 As String, St2 As String
   
   St1 = "AL"
   St2 = "IY"
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      If InStr(1, Cl, St1, 1) > 0 And InStr(1, Cl.Offset(, 4), St2, 1) > 0 Then
         Cl.Offset(, 4) = "abcd"
      End If
   Next Cl
End Sub
 
Upvote 0
Better yet
Code:
Sub sachavez()
   With Range("A1:E1")
      .AutoFilter 1, "*AL*"
      .AutoFilter 5, "*IY*"
      .Parent.AutoFilter.Range.Columns(5).SpecialCells(xlVisible).Value = "abcd"
   End With
End Sub
 
Upvote 0
Went with this one first, and it's genius! Thank you very much for the help!


Better yet
Code:
Sub sachavez()
   With Range("A1:E1")
      .AutoFilter 1, "*AL*"
      .AutoFilter 5, "*IY*"
      .Parent.AutoFilter.Range.Columns(5).SpecialCells(xlVisible).Value = "abcd"
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top