0

最近,我在这个宏上遇到了一个非常令人沮丧的问题。我将运行宏,它会完全按预期工作,但是当我重置它(设置按钮删除和清除工作表)并尝试使用完全相同的数据再次运行它时,我得到一个运行时错误“1004”:应用程序定义或对象定义错误。它突出了我的价值观之一,尽管搜索了几个小时,但我仍然找不到任何东西。我的床单没有受到保护,被这样的成功取笑真是令人沮丧。任何投入将不胜感激!

另外值得注意的是,这是一个相当大的范围,我不得不应用自动过滤器并隐藏一堆列以防止它达到 65k 公式的限制。谢谢!

Sub AddMDS()
'Uses SUMIF to find MDS and pair

    Dim LastRow As Long
    Dim LastRow2 As Long
    Rows("1:1").Select
    Range("I1").Activate
    Selection.AutoFilter
    LastRow = Cells(Rows.Count, "A").End(xlUp).row
    ActiveSheet.Range("A1:DV" & LastRow).AutoFilter Field:=19, Criteria1:= _
        "Quantity"

    LastRow2 = Cells(Rows.Count, "A").End(xlUp).row
    Range("V4:DQ" & LastRow2).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=SUMIFS(MDS!C17,MDS!C5,RC5,MDS!C14,R1C)"
    Range("V4:DQ" & LastRow2).SpecialCells(xlCellTypeVisible).NumberFormat = "#,##0"

End Sub
Sub ConvVals()
'Converts sumifs to values to enhance speed
    Dim LastRow As Long
    Dim LastRow2 As Long
    Dim lastrow3 As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).row
    ActiveSheet.Range("A1:DV" & LastRow).AutoFilter Field:=19
    LastRow2 = Cells(Rows.Count, "A").End(xlUp).row
    Range("V4:CC" & LastRow2).value = Range("V4:CC" & LastRow2).value
    lastrow3 = Cells(Rows.Count, "A").End(xlUp).row
    Range("CD4:DT" & lastrow3).value = Range("CD4:DT" & lastrow3).value
    Cells.EntireColumn.Hidden = False

End Sub

忘了提到价值对价值与第一个 LastRow 完美配合,它在第二个失败。我的第一个想法是它达到了独特字符的范围限制,这就是我打破范围的原因,但即便如此它仍然没有意义。

4

1 回答 1

0

所以我看到了这一点,意识到我从来没有展示过我的解决方案,我向大家道歉。我最终自己做了一个解决方法,我只是将整个工作表按值复制并粘贴到一个新工作表中。我仍然不知道为什么这个不起作用,但粘贴到另一张纸上肯定会起作用。希望在某处有所帮助!

于 2013-08-06T12:09:34.927 回答