這是我的代碼。代碼本身似乎工作,但由於某種原因,條件語句在第32645行後停止。我嘗試將所有變量切換爲Long,並沒有幫助。VBA循環有條件停止在任意數量的行之後被評估
另外,如果我使代碼在第32646行開始,但隨後在隨後的一行(〜18000)處停止,代碼將起作用。它所停止的數據似乎沒有相似之處。最初我嘗試了一個指定開始和結束行的for循環,但是這也不起作用,所以我嘗試了while循環(理論上都應該可以,但似乎都不行)。
它需要能夠處理130,000 +行,任何想法爲什麼這可能會發生?
的問題
迴路沒有錯誤,並通過添加一個消息框停止運行,我知道我行增加變量在最後一行結束了,但根據工作簿時,條件語句停止在後評估任意數量的行。
如果我從第一次運行停止的下一行開始運行腳本,它可以工作,但同樣適用於(可能不同)任意數量的步驟。
注
我已經做了我所有的變量 「龍」 型。我使用Option Explicit。
data_row = CLng(InputBox("Please enter the row number of the first data entry"))
Worksheets.Add(After:=Worksheets(1)).name = "Formatted_Output"
Set ws = Sheets("Formatted_Output")
Worksheets(1).Activate
LastCol = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).row
data_col = LastCol
'loop through entries to get account and permissions
increment = data_row
Do Until increment = LastRow
If Cells(data_row, data_col) = "" Then
data_col = data_col - 1
Else
' ~> For illegal ==> access denied permission that throws errors
If Cells(data_row, data_col).Value = "==>access denied" Then
permissions = "access denied" 'remove illegal =
ws.Cells(output_row, 3).Value = permissions 'print permissions to output file
Else
permissions = Cells(data_row, data_col).Value 'cell should be permission cell of each row
ws.Cells(output_row, 3).Value = permissions 'print permissions to output file
End If
data_col = data_col - 1 'domain/account cell is now highlighted
If InStrRev(Cells(data_row, data_col).Value, "?") > 0 Then
account = Split(Cells(data_row, data_col).Value, "?")(1) & Str(unknown_count) ' separate domain name and unknown id
unknown_count = unknown_count + 1 ' counting the number of unkown accounts found
ws.Cells(output_row, 2) = account 'print unknown account Id to output
domain_bit = Split(Cells(data_row, data_col).Value, "?")(0) '' get separate domain name from id cell
data_col = data_col - 1 'domain second from end cell is now highlighted
Do While data_col > 0 'generate domain from rest of row
domain_bit = Cells(data_row, data_col).Value & domain_bit 'domain built backwards
data_col = data_col - 1 'check next column for more of location name
Loop
ws.Cells(output_row, 1) = domain_bit
'data_col = LastCol
'data_row = data_row + 1
'output_row = output_row + 1
ElseIf InStrRev(Cells(data_row, data_col).Value, "\") > 0 Then
account = Split(Cells(data_row, data_col).Value, "\")(1) 'separate account ID
ws.Cells(output_row, 2) = account 'print account ID to oputput
domain_bit = Split(Cells(data_row, data_col).Value, "\")(0)
data_col = data_col - 1 'domain second from end cell is now highlighted
Do While data_col > 0 'generate domain from rest of row
domain_bit = Cells(data_row, data_col).Value & domain_bit 'domain built backwards
data_col = data_col - 1 'check next column for more of location name
Loop
ws.Cells(output_row, 1) = domain_bit 'output to file
Else
account = Cells(data_row, data_col).Value 'account is just whole cell whether empty or one word no path
ws.Cells(output_row, 2) = account 'print account ID to oputput
data_col = data_col - 1 'domain second from end cell is now highlighted (since no domain in account cell)
Do While data_col > 0 'generate domain from rest of row
domain_bit = Cells(data_row, data_col).Value & domain_bit 'domain built backwards
data_col = data_col - 1 'check next column for more of location name
Loop
ws.Cells(output_row, 1) = domain_bit 'output to file
End If
data_col = LastCol
data_row = data_row + 1
output_row = output_row + 1
End If
'Next increment
ws.Range("E" & 1) = unknown_count
increment = increment + 1
If increment = LastRow Then
MsgBox (Str(increment) & "=" & Str(LastRow))
End If
Loop
32646將是正確的2^15的邊界,例如上一個有符號的16位整數。你可能錯過了某個地方的'長'定義,所以你仍然在處理16位整數,而不是整個日誌。 – 2013-03-05 16:16:07
簡單的問題 - 這似乎非常接近'Integer'數據類型的上限 - 您是否將所有計數器定義爲'Long'?這可能是你的問題... – 2013-03-05 16:17:19
嗨,感謝評論。我將每個數字定義爲Long。 Ctrl-F整數,沒有結果了。這是令人困惑的部分,因爲我認爲肯定是問題所在。 – 4lert 2013-03-05 16:22:48