开发者

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

  1. Select cell A1
  2. Click on the Home tab in the Ribbon
  3. Click on the 'Find & Select' icon and select 'Replace'
  4. Click on the 'Options' button
  5. Enter the text to search for 'abc' in the 'Find What' box
  6. Enter the text to replace 'abc' with in the 'Replace with' box
  7. Make sure that the tick boxes are not ticked
  8. Make sure Within = Sheet, Search = By Rows and Look in = Formulas
  9. Click on the 'Replace all' button

excel macro to search for specific string


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜