excel宏来搜索特定的字符串

时间:2022-09-13 08:35:12

i need to write and excel macro to search for a string and replace it with another... how do i do this ? HELP :/

我需要编写和excel宏来搜索字符串并将其替换为另一个...我该怎么做?帮帮我 :/

2 个解决方案

#1


2  

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.

您可以记录该操作,并按Alt + Shift + F11打开脚本编辑器,然后引用记录器生成的代码。我想这可以给你一些提示。

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.

而且我认为你不需要使用Macro。只需使用“查找和替换”菜单项,然后选择所需的选项即可。

#2


2  

Using user interface in Excel 2007

在Excel 2007中使用用户界面

  1. Select cell A1
  2. 选择单元格A1

  3. Click on the Home tab in the Ribbon
  4. 单击功能区中的“主页”选项卡

  5. Click on the 'Find & Select' icon and select 'Replace'
  6. 点击“查找并选择”图标,然后选择“替换”

  7. Click on the 'Options' button
  8. 单击“选项”按钮

  9. Enter the text to search for 'abc' in the 'Find What' box
  10. 在“查找内容”框中输入要搜索“abc”的文本

  11. Enter the text to replace 'abc' with in the 'Replace with' box
  12. 在“替换为”框中输入要替换“abc”的文本

  13. Make sure that the tick boxes are not ticked
  14. 确保没有勾选勾选框

  15. Make sure Within = Sheet, Search = By Rows and Look in = Formulas
  16. 确保Within = Sheet,Search = By Rows和Look in = Formulas

  17. Click on the 'Replace all' button
  18. 单击“全部替换”按钮

excel宏来搜索特定的字符串


Using VBA code

使用VBA代码

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

#1


2  

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.

您可以记录该操作,并按Alt + Shift + F11打开脚本编辑器,然后引用记录器生成的代码。我想这可以给你一些提示。

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.

而且我认为你不需要使用Macro。只需使用“查找和替换”菜单项,然后选择所需的选项即可。

#2


2  

Using user interface in Excel 2007

在Excel 2007中使用用户界面

  1. Select cell A1
  2. 选择单元格A1

  3. Click on the Home tab in the Ribbon
  4. 单击功能区中的“主页”选项卡

  5. Click on the 'Find & Select' icon and select 'Replace'
  6. 点击“查找并选择”图标,然后选择“替换”

  7. Click on the 'Options' button
  8. 单击“选项”按钮

  9. Enter the text to search for 'abc' in the 'Find What' box
  10. 在“查找内容”框中输入要搜索“abc”的文本

  11. Enter the text to replace 'abc' with in the 'Replace with' box
  12. 在“替换为”框中输入要替换“abc”的文本

  13. Make sure that the tick boxes are not ticked
  14. 确保没有勾选勾选框

  15. Make sure Within = Sheet, Search = By Rows and Look in = Formulas
  16. 确保Within = Sheet,Search = By Rows和Look in = Formulas

  17. Click on the 'Replace all' button
  18. 单击“全部替换”按钮

excel宏来搜索特定的字符串


Using VBA code

使用VBA代码

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