excel macro to search for specific string
i need to write and excel macro to search for a string and replace it with a开发者_开发百科nother... how do i do this ? HELP :/
You can record that operations, and Alt+Shift+F11 to open the Script Editor, then reference the code generated by the Recorder. I think that can give you some hints.
And I think you don't need to use Macro. It is enough to use the "Find and Replace" Menu Item, and choose the option you want.
Using user interface in Excel 2007
- Select cell A1
- Click on the Home tab in the Ribbon
- Click on the 'Find & Select' icon and select 'Replace'
- Click on the 'Options' button
- Enter the text to search for 'abc' in the 'Find What' box
- Enter the text to replace 'abc' with in the 'Replace with' box
- Make sure that the tick boxes are not ticked
- Make sure Within = Sheet, Search = By Rows and Look in = Formulas
- Click on the 'Replace all' button
Using VBA code
Sub Replace_abc()
Sheets("Sheet1").Select
Range("A1").Select
Cells.Replace What:="abc", Replacement:="def", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
精彩评论