运行时错误“6”:溢出错误

代码工作得很好,直到几天前,但现在得到的主题行错误。 帮帮我?

Sub CopyRows() Dim bottomL As Integer Dim x As Integer bottomL = Sheets("Pacer").Range("L" & Rows.Count).End(xlUp).Row: x = 1 Dim c As Range For Each c In Sheets("Pacer").Range("A1:L" & bottomL) If (c.Value = "AFSB" Or c.Value = "TEIGIP4T" Or c.Value = "EPP") Then Intersect(c.Parent.Columns("A:Q"), c.EntireRow).Copy Worksheets("Portfolio").Range("A" & x + 1) x = x + 1 End If Next c End Sub 

尝试这个

 Option Explicit Sub CopyRows() Dim bottomL As Long Dim x As Long bottomL = Sheets("Pacer").Range("L" & Rows.CountLarge).End(xlUp).Row: x = 1 Dim c As Range For Each c In Sheets("Pacer").Range("A1:L" & bottomL) If (c.Value = "AFSB" Or c.Value = "TEIGIP4T" Or c.Value = "EPP") Then Intersect(c.Parent.Columns("A:Q"), c.EntireRow).Copy Worksheets("Portfolio").Range("A" & x + 1) x = x + 1 End If Next c End Sub 

原因在这里解释

variablesbottomL As Integer

超过32,767行的时候会发生溢出错误。 尝试声明它很长

bottomL As Long

编辑:该规则适用于X以及它正在增加。