cancel
Showing results for 
Search instead for 
Did you mean: 

Excel Macro Question

OliverMohajeri
Level 4
Hi, I've been using an Excel macro to remove NA/NV rows from my worksheet: '----------------------------------------------------------- ' ExcludeNV - Removes rows with #NA in column D '----------------------------------------------------------- Sub ExcludeNV() Dim lRows As Long, lRow As Long          Application.ScreenUpdating = False     Worksheets("Customer Details").Activate     lRows = ActiveSheet.UsedRange.Rows.Count     ' scans rows from the end upwards for proper indexing     For lRow = lRows To 2 Step -1         If IsError(Cells(lRow, 4).Value) Then _             If Cells(lRow, 4).Value = CVErr(xlErrNA) Then _                 Rows(lRow).Delete Shift:=xlUp     Next lRow End Sub     However, this is causing Excel to hang. Any ideas why?   Thanks, Oliver
1 REPLY 1

NicholasZejdlik
Level 9
Don't forget to set Application.ScreenUpdating to true at the end of the macro. I've found it best to include an error handler to re-enable it, in case the macro fails for some reason. Something like this: Sub Macro()     On Error Goto MacroError     Application.ScreenUpdating = False     ' Do macro stuff....   MacroError:     Application.ScreenUpdating = True End Sub   If it still appears to hang, try stepping through the macro with the Excel debugger to see where the hold up is.