Excel在IF语句中挂起

时间:2016-01-08 09:21:28

标签: excel vba

我从文件中读取数据并检查记录是否已存在于工作表中。

Excel处理大约60k记录后冻结。如果我开始从地点宏停止读取文件,它会在读取另外60k记录后再次冻结。

Sub aktualizacja()
    Dim koniec As Long, dlugosc As Long, pozycja As Long, numer As Long, numer2 As Long, i As Long
    Open "C:\bazy\test.dat" For Binary Access Read As #1
    dlugosc = FileLen("C:\bazy\test.dat")
    pozycja = 41
    Do
        koniec = Worksheets("Baza").Range("A1048576").End(xlUp).Row
        Get #1, pozycja, numer
        Get #1, pozycja + 4, numer2
        For i = 2 To koniec
            If Worksheets("Baza").Cells(i, 1) = numer Then
                'If Worksheets("Baza").Cells(i, 2) <> numer2 Then
                '    Worksheets("Baza").Cells(i, 2) = numer2
                'End If
                'Cells(1, 11) = i
                'Exit For
            End If
        Next i
        If i > koniec Then
            Worksheets("Baza").Cells(koniec + 1, 1) = numer
            Worksheets("Baza").Cells(koniec + 1, 2) = numer2
        End If
        pozycja = pozycja + 40
    Loop Until (pozycja > dlugosc)
    Close #1
End Sub

当我将所有命令放在IF语句中时,宏仍然会冻结。

1 个答案:

答案 0 :(得分:0)

如何添加类似

的内容
If i Mod 1000 = 0 Then DoEvents
在循环中

以防止锁定?

相关问题