获取“下标超出范围”

时间:2016-10-10 14:36:49

标签: excel vbscript

当我运行此代码时,我收到“下标超出范围”。 (问题在于LastRow

的定义
my_new_string = "xyz"
my_old_string = "abc"

For Each objsheet1 In objworkbook1.Sheets
  With objsheet1
    If .Name = "Name1" Then
      On Error Resume Next
      LastRow = .Cells.Find("*",.Range("A1"),xlPart,xlFormulas,xlByRows,xlPrevious,False).Row
      MsgBox "Error: " & Err.Number & " (" & Err.Source & ") - " & Err.Description

      For i = 1 To LastRow Step 1
        For j = 1 To 10 Step 1
          If InStr(1, .Cells(i, j).Value, my_old_string) Then
            .Cells(i, j).Value = Replace(.Cells(i, j).Value, my_old_string, my_new_string)
          End If
        Next
      Next 
    End If
  End with
Next

这个错误意味着什么,我该如何解决?

0 个答案:

没有答案