Lastrow大于3000会产生错误

时间:2017-11-16 16:05:35

标签: excel vba

以下代码适用于任何LastRow值小于3000(约)但当我将值更改为更高的数字时失败。我需要LastRow值大约为100000

当我将计数器更改为更高的值时,我得到了

  

错误1004(应用程序或对象定义错误)

任何原因?

Sub InsertRow()

    Dim Col As Variant
    Dim BlankRows As Long
    Dim LastRow As Long
    Dim R As Long
    Dim StartRow As Long
    Application.ScreenUpdating = False
        Col = "A"
        StartRow = 1

        LastRow = 10000
        Worksheets("Output").Activate


        With Worksheets("Output")
           For R = LastRow To StartRow Step -1
                If Cells(R, Col) = 1 Then
                    Cells(R, Col).EntireRow.Insert Shift:=xlDown
                    Cells(R, 1) = 0
                    Cells(R, 2) = Cells(R + 1, 2)

            Next R
        End With
        Range("A1").Activate
        Dim LR As Long, LC As Long
        LR = ActiveCell.End(xlDown).Row
        LC = ActiveCell.End(xlToRight).Column

        Worksheets("Output").Range("A1", Cells(LR, LC)).Copy Destination:=Worksheets("Trans").Range("A1")


Application.ScreenUpdating = True

End Sub

0 个答案:

没有答案