簡體   English   中英

關於 VBA(Excel 宏)中的循環限制的問題

[英]Question about Loop Limit in VBA (Excel Macro)

毫無疑問,我的代碼可以更簡單,更好地編寫序言。 盡管如此,除了遇到硬循環限制之外,它可以完美地完成工作並且工作得很好。 簡而言之,目標是寫下給定商店的日期並循環瀏覽商店中的所有日期。 有關示例輸入,請參見圖 1示例 1 - 現在輸入output 數據只需返回列中的日期。 我有代碼的其他部分已經格式化和修復了一些東西,所以這部分只需要每列寫入日期 1,請參閱示例 2示例 2 中的示例 output - 所需的 Output

同樣,代碼運行良好,除了它遇到問題並且不會 output 超過 373 行,我知道有限制,但對於簡單的嵌套循環,我希望數字能達到數千。 現在這是唯一商店 ID,對於它檢查的其他數據,它大約停止在 1469 行左右。 一個更大的數字,但從我可以在線研究的內容來看,我應該還沒有達到任何限制。 有什么我不正確地使用來增加我的限制嗎? 我對格式中的任何錯誤表示歉意,因為我是編碼和堆疊溢出社區的新手。

Sub MissingDates()
'SubRoutine to check for missing Dates
Dim store As String
Dim storeunique As String
Dim missdat As String
Dim str As String
'Store = Store_ID; missdat = missing Date; Storeunique = Nonduplicate store column

'cel As Range
Dim i As Integer
Dim x As Integer
Dim j As Integer
Dim n As Integer
Dim a As Integer


x = 1
'x = 253
j = 0
'j = 150
i = 1

For i = 1 To 400


    store = Range("A" & x + 3).Value
    storeunique = Range("E" & i + 3).Value
    If storeunique = "" Then
        Exit For
    ElseIf store = storeunique Then
        For n = 1 To 31
        'n - Column of Dates to be checked against
            store = Range("A" & x + 3).Value

            If store = storeunique Then
                missdat = Range("B" & x + 3).Value
                a = Len(missdat)
                str = Left(missdat, a - 5)

                Cells(j + 4, n + 6).Value = str
            Else
                Exit For
            End If
            '
            x = x + 1
        Next n

    End If
        j = j + 1

Next i
End Sub

通過查看您的代碼和您提供的詳細信息,您很可能遇到了以下退出條件:

If storeunique = "" Then
    Exit For

您是否檢查過,當您分配“storeunique”值時,您沒有意外遇到空白單元格?

您說得對,因為行數(原始帖子中的 1469 行)遠低於 integer 的最大值 32,767(更多關於 Microsoft 文檔中數據值)。如果是這種情況,您會遇到溢出錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM