ThrottleWorks
Excel Ninja
Hi,
I am running below code.
This code is run on two different locations.
On one location code runs fine.
However at another location macros face bug at 'T_Sht.AutoFilterMode = False' line.
Also this bug is not permanent, sometimes macro will face bug and sometime macro will not face any issue while running.
Not able to understand why this is happening.
Can anyone please help me in this.
I am running below code.
This code is run on two different locations.
On one location code runs fine.
However at another location macros face bug at 'T_Sht.AutoFilterMode = False' line.
Also this bug is not permanent, sometimes macro will face bug and sometime macro will not face any issue while running.
Not able to understand why this is happening.
Can anyone please help me in this.
Code:
Sub Test()
Dim TempLr As Long
Dim TempCol As Long
Dim TempRng As Range
Set T_Sht = ThisWorkbook.Worksheets("T Sheet")
ThisWorkbook.Activate
T_Sht.Select
On Error Resume Next
If ActiveSheet.Name <> "T Sheet" Then
MsgBox "T Sheet not present in the macro", vbCritical
End
End If
On Error GoTo 0
TempCol = 10 'Change column reference
TempLr = T_Sht.Cells(T_Sht.Rows.Count, 1).End(xlUp).Row
Set TempRng = T_Sht.Range(T_Sht.Cells(1, 1), T_Sht.Cells(TempLr, 30))
TempRng.AutoFilter Field:=TempCol, Criteria1:="=#N/A", Operator:=xlOr, Criteria2:="="
TempLr = T_Sht.Cells(T_Sht.Rows.Count, 1).End(xlUp).Row
If TempLr <> 1 Then
Set TempRng = T_Sht.Range(T_Sht.Cells(2, 1), T_Sht.Cells(TempLr, 30))
TempRng.SpecialCells(xlCellTypeVisible).Delete
End If
On Error Resume Next
T_Sht.AutoFilterMode = False
T_Sht.AutoFilterMode = False
On Error GoTo 0
End Sub