VBA - is there a way to clean up this code?

storemannequin

Board Regular
Joined
May 29, 2010
Messages
108
I recorded this find & replace with the recorder than added in a variable of my own, but is there a way to do this w/o resorting to the recorder?


Sub ReplaceTitles()
FC = Cells(1, Columns.Count).End(xlToLeft).Column

Set Rng = Range(Cells(1, 1), Cells(1, FC))

With Rng

.Replace What:="Matrix", Replacement:="Overhead", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
.Replace What:="Net ", Replacement:="Catch", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
.Replace What:="Little league", Replacement:= _
"ASP", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False

End With


End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Sub ReplaceTitles()
    With [A1].CurrentRegion.Rows(1)
        .Replace "Matrix", "Overhead", xlPart
        .Replace "Net ", "Catch"
        .Replace "Little league", "ASP"
    End With
End Sub
 
Upvote 0
What do you mean?

How us that code resorting to the recorder?

It might have been generated by it but that's it, the recorder isn't anything to do with it now.
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,510
Members
452,918
Latest member
Davion615

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