小さなVBAマクロを作成して2枚のワークシートを比較し、独自の値を新しい第3ワークシートに配置しました。 コードは機能しますが、Excelが「応答しない」と表示され、30〜45秒後に復帰し、すべてが正常に動作した場合はいつでも使用します。最初のVBAコード...より速くなるようにフィードバックを探しています
この処理を高速化し、「応答しない」問題を取り除くことはできますか?私のコンピュータは十分に速くないのですか?
私は比較している各シートで約2500-2700行から始めます。
Sub FilterNew()
Dim LastRow, x As Long
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "New" 'Adds a new Sheet to store unique values
Sheets(1).Rows("1:1").Copy Sheets("New").Rows("1:1") 'Copies the header row to the new sheet
Sheets(1).Select
LastRow = Range("B1").End(xlDown).Row
Application.ScreenUpdating = False
For Each Cell In Range("B2:B" & LastRow)
x = 2 'This is for looking through rows of sheet2
Dim unique As Boolean: unique = True
Do
If Cell.Value = Sheets(2).Cells(x, "B").Value Then 'Test if cell matches any cell on Sheet2
unique = False 'If the cells match, then its not unique
Exit Do 'And no need to continue testing
End If
x = x + 1
Loop Until IsEmpty(Sheets(2).Cells(x, "B"))
If unique = True Then
Cell.EntireRow.Copy Sheets("New").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next
Application.ScreenUpdating = True
End Sub
パフォーマンスの問題あなたはアーカンソー言い換えれば、コードを文書化している人々を見て爽やかです。よくやった!!! – FDavidov
一時変数を使用して値を保存し、新しい値を一度に貼り付けると、すべてのループサイクルで行をコピーし、行をコピーし、行を貼り付けます。 – Hackerman
コードが意図したとおりに動作し、パフォーマンスを含むコードのあらゆる側面についてのフィードバックを探していますが、[codereview.se]は投稿したい場所です。 **あなたがタイトル**のコードの目的を述べて、コードが何をしているのかを説明してください。 –