2016-08-04 17 views
0

Ich benutze unten Code in VBA, aber es dauert zu viel Zeit zu laufen. Report haben 8 Blätter und 450+ Zeilen sollten in jedem Blatt eingecheckt werden.Brauchen Alternative Code für For Loop

Sub forloop() 
Application.ScreenUpdating = False 
Application.DisplayAlerts = False 
Application.Calculation = xlCalculationManual 
lr = Cells(Rows.Count, 3).End(xlUp).Row - 1 
For s = 1 To Sheets.Count 
    For x = lr To 1 Step -1 
     If Cells(x, 2) <> "" Then 
     Cells(x, 2).EntireRow.Delete 
    Next x 
Next s 
Application.ScreenUpdating = True 
Application.DisplayAlerts = True 
Application.Calculation = xlCalculationAutomatic 
End Sub 

Können Sie mir bitte vorschlagen, alternative Methode schnell zu laufen.

+1

Hat Ihr Code, was Sie wollen? Scheint so, als ob es nur auf dem ActiveSheet läuft ... –

+0

@TimWilliams - ich öffne die erforderliche Arbeitsmappe und der Code muss auf dieser Arbeitsmappe ausgeführt werden –

+0

@TimWilliams - Ja, es muss das erste Blatt und dann das nächste Blatt bis zum letzten Blatt –

Antwort

1
dim wb as workbook, sht as worksheet, lr as long, r as long 

set wb = workbook.open(wbPathHere) 

for each sht in wb.worksheets 
    lr = sht.cells(sht.rows.count, 3).End(xlUp).row - 1 
    for r = lr to 1 step-1 
     if sht.cells(r, 2) <> "" Then sht.cells(r, 2).entirerow.delete 
    next r  
next sht