Excel VBAstring在大文档上操作导致运行时错误“1004”

所以我在RenPy上做了一个视觉小说,我不得不在整个文档上换掉句子。

由于修订版本在excel文件中,我决定使用excelmacros自动修复。 有三列。 原始行,build议的修复程序和原始脚本。

例

于是我ban出了一个如下所示的脚本:

Sub MacroVOID() Dim x As Integer Dim y As Long x = 2 y = 2 Do While x < 298 If StrComp(Cells(x, 1).Value, Cells(y, 3).Value, vBinaryCompare) = 0 Then Cells(y, 3).Value = Cells(x, 2).Value x = x + 1 Else y = y + 1 End If Loop End Sub 

这导致运行时错误“1004”。

我在工作表级别保存macros。

我是这个东西的新手,所以任何帮助,将不胜感激。

尝试这个


 Option Explicit Public Sub ReplaceStrings() Dim ws As Worksheet, cel As Range Set ws = ThisWorkbook.Worksheets("Sheet1") '<-- Update Sheet Name With ws.UsedRange For Each cel In .Columns(1).Cells 'iterate through all used cells in col A If Len(cel.Value2) > 0 Then 'if the cell is not empy 'in column 3: replace all instances of values in current cell 'with the value in (current cell).offset by one column to its right (col B) .Columns(3).Replace cel.Value2, cel.Offset(0, 1).Value2, xlWhole End If Next End With End Sub 

Range.Replace方法有这些参数:

Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat)"

帮助中的更多细节:

  • 内容 :所需变体您希望Microsoft Excelsearch的string。
  • replace :必需的变体replacestring。
  • LookAt :可选变体可以是以下XlLookAt常量之一:xlWhole或xlPart。
  • SearchOrder :可选Variant可以是以下XlSearchOrder常量之一:xlByRows或xlByColumns。
  • MatchCase :可选变体正确使search区分大小写。
  • MatchByte :可选Variant只有在Microsoft Excel中select或安装了双字节语言支持,才可以使用此参数。 如果双字节字符只匹配双字节字符,则为真。 假使双字节字符与它们的单字节等价物匹配。
  • SearchFormat :可选Variant方法的search格式。
  • ReplaceFormat :可选Variant该方法的replace格式。