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中使用用户界面
- 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
选择单元格A1
单击功能区中的“主页”选项卡
点击“查找并选择”图标,然后选择“替换”
单击“选项”按钮
在“查找内容”框中输入要搜索“abc”的文本
在“替换为”框中输入要替换“abc”的文本
确保没有勾选勾选框
确保Within = Sheet,Search = By Rows和Look in = Formulas
单击“全部替换”按钮
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中使用用户界面
- 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
选择单元格A1
单击功能区中的“主页”选项卡
点击“查找并选择”图标,然后选择“替换”
单击“选项”按钮
在“查找内容”框中输入要搜索“abc”的文本
在“替换为”框中输入要替换“abc”的文本
确保没有勾选勾选框
确保Within = Sheet,Search = By Rows和Look in = Formulas
单击“全部替换”按钮
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