私が終了する前に15万反復を実行するように設計されたマクロを(下)持っているのXの数よりも多くの後にクラッシュし。ただし、繰り返し回数が1,000回を超えるコードを実行すると、Excelは「応答しない」モードに移行し、クラッシュします。私は12時間以上それを残しましたが、それ以上は良くなりません。このコードは以前は最初の100,000回の反復を実行するために使用されていましたが、250,000回の段階で1,048,576回の反復を実行する必要があります。エクセル2010は、ループ
クラッシュ(私はそれらを同時に実行を停止しましたが、それでもクラッシュ)も見通し、IEだけでなく、Chromeをダウンさせます。
私はF5を経由してF8を経由して、またはチェックポイントにコードを実行すると、コードが細かい実行されます。しかし、これは948,576回繰り返すと実用的ではありません。
それは常にクラッシュしないように、問題を解決する方法上の任意の提案?
システムの仕様は以下のとおりです。 エクセル2010 のi5(第三世代) 8ギガバイトのRAM
コード:これはちょうど12
のうち10
列を移入するために私に5秒未満を取った
Dim a As Variant
Dim b As Variant
Dim c As Variant
Dim d As Variant
Dim e As Variant
Dim i As Integer
Dim j As Double
Dim strResult As Double
a = 1
b = 100001
While b <= 250000
While a <= 12
If a = 1 Then
If Cells(b, 14) = "EEEE" Then
Cells(b, a) = 1234
ElseIf Cells(b, 14) = "ZYXW" Then
Cells(b, a) = 2468
ElseIf Cells(b, 14) = "AAAA" Then
Cells(b, a) = 3579
ElseIf Cells(b, 14) = "BBBB" Then
Cells(b, a) = 9764
ElseIf Cells(b, 14) = "DDDD" Then
Cells(b, a) = 8631
Else
Cells(b, a) = "ZZZZ"
End If
ElseIf a = 2 Then
If Cells(b, 15) = 5 Then
Cells(b, a) = "JPY"
ElseIf Cells(b, 15) = 4 Then
Cells(b, a) = "GBP"
ElseIf Cells(b, 15) = 3 Then
Cells(b, a) = "CHF"
ElseIf Cells(b, 15) = 2 Then
Cells(b, a) = "USD"
ElseIf Cells(b, 15) = 1 Then
Cells(b, a) = "EUR"
Else
Cells(b, a) = "YYYY"
End If
ElseIf a = 3 Then
If Cells(b, 16) = 10234 Then
Cells(b, a) = "A27Z2"
ElseIf Cells(b, 16) = 10420 Then
Cells(b, a) = "B28Y"
ElseIf Cells(b, 16) = 10432 Then
Cells(b, a) = "C29X"
ElseIf Cells(b, 16) = 18953 Then
Cells(b, a) = "D30W"
ElseIf Cells(b, 16) = 21048 Then
Cells(b, a) = "E31V"
ElseIf Cells(b, 16) = 36542 Then
Cells(b, a) = "F32U"
ElseIf Cells(b, 16) = 36954 Then
Cells(b, a) = "G33T"
ElseIf Cells(b, 16) = 65425 Then
Cells(b, a) = "H34S"
ElseIf Cells(b, 16) = 75963 Then
Cells(b, a) = "I35R"
ElseIf Cells(b, 16) = 84563 Then
Cells(b, a) = "J36Q"
Else
Cells(b, a) = "XXXX"
End If
ElseIf a = 4 Then
strResult = 1
For i = 1 To Len(Cells(b, 18))
Select Case Asc(Mid(Cells(b, 18), i, 1))
Case 65 To 90:
strResult = strResult + Asc(Mid(Cells(b, 18), i, 1)) - 64
Case Else
strResult = strResult + Mid(Cells(b, 18), i, 1)
End Select
Next
j = WorksheetFunction.CountIfs(Range("A1:A" & b), Range("A" & b), Range("B1:B" & b), Range("B" & b))
Cells(b, a) = Cells(b, 1) & " - " & Cells(b, 2) & strResult & " - " & j
ElseIf a = 5 Then
Cells(b, a) = Cells(b, 17)
ElseIf a = 6 Then
If Cells(b, 19) = "SB" Then
Cells(b, a) = "Sub"
ElseIf Cells(b, 19) = "RD" Then
Cells(b, a) = "Red"
Else
Cells(b, a) = "XXXX"
End If
ElseIf a >= 7 Then
Cells(b, a) = Cells(b, a + 13)
End If
a = a + 1
Wend
b = b + 1
a = 1
Wend
Columns("M:Q").Select
Selection.Delete Shift:=xlToLeft
Columns("N:V").Select
Selection.Delete Shift:=xlToLeft
1)クラッシュ何を確認してください。あまりにも多くのリソースを使用している、または使用OKですが、マクロが長くかかるのでExcelが応答しなくなり、Excelを応答させようとしてクラッシュします。それがちょうど非常に長いマクロで、その状態を確認できるようにするには、しばらくの間、毎回 'DoEvents'を追加することを検討してください。 2)コードをスピードアップします。ここでは 'Cells'への参照がたくさんあり、配列の格納やアクセスよりも時間がかかります。最適化の詳細については、姉妹サイトCode Reviewをご覧ください。 – Mikegrann
@Mikegrann 1)アイドル時のリソース使用率は2〜6%です。私がコードを実行しているとき、それは75〜95%の間で発生し、4つのプロセッサーのうち3つが10秒間完全に実行されます。その後、約25%に低下しますが、応答しません。 Crtl + BrkまたはESCをクリックすると、システムがクラッシュします。 2)どのように私はこの配列を使用するかわからない。アドバイスできますか? – Clauric
32ビット版または64ビット版のExcel? –