VBA Find and replace but only certain cells

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,201
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have this bit of code that finds a word then removes other parts from the sentance in the cell, but I need it to find all of them not just one.

here is the code:

Code:
Sub Testit1()
Set rngX11 = ActiveSheet.Cells.Find("Structure", lookat:=xlPart)
rngX11.Replace What:="""", Replacement:="", lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
rngX11.Replace What:=".", Replacement:="", lookat:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

End Sub

So as you can see it looks for the word
"Structure" anywhere in the sheet, and when it finds it it replaces all "" with nothing and all . with nothing
but I have more than one word of
"Structure" and I need it to do this with everyone.
I can't just use replace on the sheet as there is data that needs the . and the ""

the cell will always begin with the word
Structure if that helps.

Please help if you can

Thanks

Tony
<strike>
</strike>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Maybe this:

Code:
Sub testtt()
Dim sAddress As String, rngX11 As Range

Set rngX11 = ActiveSheet.Cells.Find("Structure", lookat:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False)
If Not rngX11 Is Nothing Then
    sAddress = rngX11.Address
    Do
       Set rngX11 = Cells.FindNext(rngX11)
           rngX11 = Replace(Replace(rngX11, """", ""), ".", "")

    Loop While rngX11.Address <> sAddress
End If
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,799
Messages
6,126,975
Members
449,351
Latest member
Sylvine

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