Excel宏与大数据集崩溃

时间:2017-09-06 02:14:18

标签: excel excel-vba vba

我写了一个用于分析二维液压流模型输出的宏。它摆脱了垃圾数据并将我想要分析的数据移动到网页的“原点”附近。当我们有一个3英寸大小的网格时,它处理了一个非常大的数据集,但是当我在1'大小的矩阵的输出上运行时,excel崩溃了。在运行宏之前,它的大小约为4500 x 4500个单元格。宏看起来像:

Sub removeinplace()
    'This sub replaces all of the junk data (-9999) with blank cells but does not affect 
    'cells that do not have (-‘9999) in them.
    'This sub calls DeleteBlankColumns and DeleteBlankRows to move the cluster (it is 
    'a contiguous cluster) of data closer to the origin where I can work with it.

    ' define Myrange
    Set MyRange = ActiveSheet.UsedRange

    With ActiveSheet.UsedRange
        .Replace -9999, "", xlWhole, SearchFormat:=False, ReplaceFormat:=False
    End With

    Call DeleteBlankColumns
    Call DeleteBlankRows
End Sub


Sub DeleteBlankColumns()
    'This sub deletes blank columns

    'Step1: Declare your variables.
    Dim iCounter As Long
    Dim MaxColumns As Long

    'Step 2: Define the target Range.
    With ActiveSheet
        MaxColumns = ActiveSheet.Range("B1").Value

        'Step 3: Start reverse looping through the range.
        For iCounter = MaxColumns To 1 Step -1
            'Step 4: If entire column is empty then delete it.
            If Application.CountA(Columns(iCounter).EntireColumn) = 0 Then
                Columns(iCounter).Delete
            End If
        'Step 5: Increment the counter down
        Next iCounter
    End With
End Sub


-------------------------------------------------------------
Sub DeleteBlankRows()
    'This sub deletes blank rows.

    'Step1: Declare your variables.
    Dim iCounter As Long
    Dim MaxRows As Long

    'Step 2: Define the target Range.
    With ActiveSheet
        MaxRows = ActiveSheet.Range("B2").Value

        'Step 3: Start reverse looping through the range.
        For iCounter = MaxRows To 1 Step -1
            'Step 4: If entire row is empty then delete it.
            If Application.CountA(Rows(iCounter).EntireRow) = 0 Then
                Rows(iCounter).Delete
            End If
        'Step 5: Increment the counter down
        Next iCounter
    End With
End Sub

我做错了什么?

(我无法加载示例数据,因为文件太大了。)

0 个答案:

没有答案