以下のコードスニペットで特にメモリ非効率なものはありますか? ExcelがLong2
の大きな値(> 50,000)に対して永遠に実行されるようにしています。それはLong2の中小値に対してはうまく動作しますが、大きな値の場合、それに比例して長い時間は実行されません。終了しないようです。 Ctrl-Breakを押すと進行状況バーが表示され、DoEvents
というコードが表示されているにもかかわらず、回転している進行状況ホイールと応答なしが返されます。このようにCountIfを使用すると、繰り返しスプレッドシートにアクセスできますか?
私はワークシートを何度も何度も読んでいますか?メモリ内にあるRange
オブジェクトを読んでいるのは私の印象ですが、間違っていれば修正してください。
私のハンガリー語表記をお許しください。
''A' and 'AV' Matches
If boolMatchesSheetExists = True Then
With ThisWorkbook.Sheets("Matches")
Long2 = Application.CountA(.Columns(1))
Set Range2 = .Range(.Cells(1, 1), .Cells(Long2, 1))
Set Range3 = .Range(.Cells(1, 19), .Cells(Long2, 19))
Set Range4 = .Range(.Cells(1, 36), .Cells(Long2, 36))
End With
For Each Cell1 In Range1
''A' Matches
If Application.CountIfs(Range2, Cell1.Value, Range3, "<>" & Cell1.Value, Range4, "A") > 0 Then
.Cells(Cell1.Row, 2).Value = 1
Else
.Cells(Cell1.Row, 2).Value = 0
End If
''AV' Matches
If Application.CountIfs(Range2, Cell1.Value, Range3, "<>" & Cell1.Value, Range4, "AV") > 0 Then
.Cells(Cell1.Row, 3).Value = 1
Else
.Cells(Cell1.Row, 3).Value = 0
End If
''A' Claims Duping Against Self
If Application.CountIfs(Range2, Cell1.Value, Range3, Cell1.Value) > 0 Then
.Cells(Cell1.Row, 4).Value = 1
Else
.Cells(Cell1.Row, 4).Value = 0
End If
Next Cell1
End If
編集:@ 200_successごとA '' AV 'の提案、このコードは、特定のタイプ(の一致かどうかのブール結果(0、1)で要約シート( "概要")を移入' '、' Self-Dup ')が見つかりました。上記のコードをよく見ると、実際には、With ThisWorkbook.Sheets("Summary")
のようなものが含まれていなければならない、欠けているWith
ブロックがあることがわかります。
コードレビューについてお聞きしたい場合がありますか? – findwindow
** Set ** ting 'Range1' –
あなたのコードが動作しているなら、あなたは作業コードを見直すための[Code Review](http://codereview.stackexhange.com)を使うのが一番良いかもしれません。つまり、使用したセルを取得するには、 'CountA'の代わりに[' Range.End(xlUp) '](http://stackoverflow.com/a/30947741/4240221)を使用してください。 –