我一直在这个宏上出现溢出错误:
Sub searchAndCopy()
Dim wbOpen As Workbook
Set wbOpen = Workbooks("ExtractedColumns.xlsm")
Dim searchString As String
searchString = "-----------------------------------------------------------------"
Dim lastRow As Integer, i As Integer
lastRow = 0
Dim thisSheet As Worksheet
Set thisSheet = Sheets("Sheet1")
Dim sh As Worksheet
For i = thisSheet.Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
If (thisSheet.Range("A" & i) = searchString) Then
If lastRow = 0 Then
lastRow = i
Else
Sheets.Add After:=Sheets(Sheets.Count)
Set sh = ActiveSheet
thisSheet.Rows(i + 1 & ":" & lastRow).Copy Destination:=sh.Rows("1:1")
thisSheet.Rows(i + 1 & ":" & lastRow).Delete
'Commenting the following code didn't affect the error, so I'm keeping them as comments until I figure it out
'Call extractSiteColumns
'For Each curr In ActiveSheet.UsedRange
'If InStr(1, curr.Value, "----") > 0 Then curr.Value = ""
'Next
lastRow = i
End If
End If
Next i
End Sub
我几乎可以肯定导致错误的是在For循环开始之前的行中,因为for循环似乎没有执行(并且我没有更改任何内容)。我唯一想要修改的是对“ExtractedColumns”工作簿的引用。
有关导致此溢出错误的原因的任何想法?