0

I'm using below code in vba but it taking too much time to run. Report have 8 sheets and 450+ rows should be check in each sheet.

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

Could you please suggest me any alternate method to run fast.

11
  • 1
    Does your code do what you want? Seems like it only operates on the ActiveSheet... Commented Aug 4, 2016 at 19:31
  • @TimWilliams - i'll open required workbook and the code need to perform on that workbook Commented Aug 4, 2016 at 19:34
  • @TimWilliams - Yes, it need to run first sheet and then next sheet until last sheet Commented Aug 4, 2016 at 19:36
  • Could you just sort the sheet instead of deleting the entire row? Commented Aug 4, 2016 at 19:39
  • @saikrishna Well, as far as making it process all Sheets goes, you could change your instances of Cells(x, 2) to Sheets(s).Cells(x, 2) - but this won't help the speed. For that, you'll have to rework the row deletion, because deleting rows is time-consuming Commented Aug 4, 2016 at 19:44

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.