调用范围对象的VBA插入方法失败/对象

时间:2014-07-01 14:24:47

标签: excel vba excel-vba

我已经阅读了很多解决方案,但没有一个有效...我的代码已经运行了2周,但现在它在以下行中失败了:     Sheets("Order Forms").Range(Cells(25 + intAbove, intCol - 3), Cells(25 + intAbove, intCol + 1)).Insert Shift:=xlDown

我尝试使用Select然后使用Selection重新编写它,但没有任何效果。如果我先运行其他一些宏,它仍然有效。我在主题中提到了两个错误。

如果有帮助,这是我的整个程序......

Sub Modify_List(ByVal intNewVal As Integer, ByVal intOldVal As Integer, strType As String, intCol As Integer)
Dim intA1 As Integer
Dim intA2 As Integer
Dim intAbove As Integer
Dim i As Integer

Application.ScreenUpdating = False

Select Case strType
    Case "Standard User Phones - Cisco 7965"
        intAbove = 0
        intCol = intCol + 1

    Case "Public Space Phones - Cisco 7965"
        intAbove = Cells(17, intCol - 1).Value
        If intAbove > 0 Then
            intAbove = intAbove + 2
        End If

    Case "Public Space Phones - Cisco 8831"
        intA1 = Cells(17, intCol - 1).Value
        intA2 = Cells(17, intCol).Value

        If intA1 + intA2 = 0 Then
            intAbove = 0
        ElseIf intA1 = 0 Then
            intAbove = intA2 + 2
        ElseIf intA2 = 0 Then
            intAbove = intA1 + 2
        Else
            intAbove = intA1 + intA2 + 4
        End If

End Select

Select Case intNewVal
    Case Is = intOldVal
        'do nothing

    Case Is < intOldVal
        'remove rows

        If intNewVal = 0 Then
            'remove header and lines
            Range(Cells(25 + intAbove, intCol - 3), Cells(26 + intAbove + intOldVal, intCol + 1)).Delete Shift:=xlUp
            Cells(20, intCol).Select
        Else
            'remove ending lines
            Range(Cells(26 + intAbove + intNewVal + 1, intCol - 3), Cells(26 + intAbove + intOldVal, intCol + 1)).Delete Shift:=xlUp
            Cells(26 + intAbove + intNewVal, intCol - 2).Select

        End If

    Case Is > intOldVal
        'add rows

        If intOldVal = 0 Then
            'add header and lines
            SheetAU.Range("B1").Value = strType
            SheetAU.Range("A1:E2").Copy
            'ActiveWorkbook.Sheets("Order Forms").Activate
            **Sheets("Order Forms").Range(Cells(25 + intAbove, intCol - 3), Cells(25 + intAbove, intCol + 1)).Insert Shift:=xlDown**
            Application.CutCopyMode = False


            For i = 1 To intNewVal
                SheetAU.Range("A3:E3").Copy
                Sheets("Order Forms").Range(Cells(26 + intAbove + i, intCol - 3), Cells(26 + intAbove + i, intCol + 1)).Insert Shift:=xlDown
                Application.CutCopyMode = False
                Cells(26 + intAbove + i, intCol - 3).Value = i
            Next

            Cells(27 + intAbove, intCol - 2).Select

        Else
            'insert extra lines
            For i = intOldVal + 1 To intNewVal
                SheetAU.Range("A3:E3").Copy
                Sheets("Order Forms").Range(Cells(26 + intAbove + i, intCol - 3), Cells(26 + intAbove + i, intCol + 1)).Insert Shift:=xlDown
                Application.CutCopyMode = False
                Cells(26 + intAbove + i, intCol - 3).Value = i
            Next

            Cells(26 + intAbove + intOldVal + 1, intCol - 2).Select

        End If

End Select

Application.ScreenUpdating = True

End Sub

0 个答案:

没有答案