Excel不会插入列

时间:2015-09-24 19:01:07

标签: excel excel-vba vba

我有一个不允许我插入新列的工作簿。这是一个支持宏的工作簿,我认为这是问题的原因。插入新列时,除了页面上的activeX按钮向右移动外没有任何反应。我该如何解决这个问题?

这是一个正在发生的事情的GIF。请注意,在右上角,每个插入按钮都会向右移动

Insert Error GIF

宏是一个循环,用于对从最高到最低转弯率的数据范围进行排序,并添加一个自由分配单位,直到没有剩余要分配。简化代码段:

 Sub SecondaryDistrLoop()
Application.ScreenUpdating = False
    'Set variables

    'Calculate the worksheet to ensure all formulas are up to date
    ActiveSheet.Calculate

    'get secondary allocation amount to distribute
    AmountToDistribute = Range("Q2")

    'get address of title cell where secondary allocaton goes (TITLED: Natl Reserve Discretionary)
     Cells.Find(What:="Natl Reserve Discretionary", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=False).Activate
    Set AllocationAdjustmentTitleCell = Range(ActiveCell, ActiveCell)


    'get address of Dec Turn Rate column to sort on
    Cells.Find(What:="Dec Turn Rate", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=False).Activate

    'get address of title cell for sorting column TITLE: (New DS on 3 Mth Avg Sales)
    SortColumnAddressString = ActiveCell.Address(Rowabsolute:=False, columnabsolute:=False)
    SortColumnReferenceString = Left(SortColumnAddressString, 1)
    ChartTitleRowNumber = Right(SortColumnAddressString, 1)



    'Find Range of dealers to be sorted - aka finding range until the national summary rows
    Cells.Find(What:="Code", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True _
    , SearchFormat:=False).Activate

    LastRow = ActiveCell.End(xlDown).Row - 1
    LastColumn = ActiveCell.End(xlToRight).Column + 17


    Set DataRange = Range(Cells(ActiveCell.Row + 1, ActiveCell.Column), Cells(LastRow, LastColumn))


    AllocationAdjustmentTitleCell.Activate

    'start loop
    Do Until AmountToDistribute = 0



    'update formulas
    ActiveSheet.Calculate

    'Sort data to bring highest days supply to the top of list - range is built of dynamically finding column name New DS on 3 mth avg sales
    DataRange.Sort key1:=Range(SortColumnReferenceString & ChartTitleRowNumber + 1 & ":" & SortColumnReferenceString & LastRow), _
       order1:=xlDescending, Header:=xlNo

    'set lowest days supply to increase secondary allocation by 1
    AllocationAdjustmentTitleCell.Offset(1, 0) = AllocationAdjustmentTitleCell.Offset(1, 0).Value + 1

    'reduce the amount to distribute by 1
    AmountToDistribute = AmountToDistribute - 1



    Loop


    Application.ScreenUpdating = True
    End Sub

1 个答案:

答案 0 :(得分:0)

从网络位置处理文件是个问题。我把文件放到了我的本地驱动器上,这一切都是固定的...茫然和困惑