The code in fact help me to delete any unwanted blank fields in my Sheet, it was working fine till yesterday but today when my workesheet had more than 2300 lines of data the code delete first 2000 rows from the sheet and gave me remaining 300 Rows.
I know the problem is in this line
Range ("A2:K2000".Select)
Is there any solution to replace this scenarios other than changing the value of K
Code
Sub Delete_blank()
With ActiveSheet
If .Autofiltermode = False Then Cells.Select
Selection.AutoFilter
ActiveSheet.Range ("$A$2:$C$") & lastrow.AutoFilter Field:=1, Criterial:="="
ActiveSheet.Range ("$A$2:$C$") & lastrow.AutoFilter Field:=2, Criterial:="="
ActiveSheet.Range ("$A$2:$C$") & lastrow.AutoFilter Field:=3, Criterial:="="
Range ("A2:K2000").Select
Selection.EntireRow.Delete
ActiveSheet.ShowAllData
.AutoFilterMode = False
End With
End Sub
'INPUT : Sheet, the worksheet we'll search to find the last row
'OUTPUT : Long, the last occupied row
'SPECIAL CASE: if Sheet is empty, return 1
Public Function LastOccupiedRowNum(Sheet As Worksheet) As Long
Dim lng As Long
If Application.WorksheetFunction.CountA(Sheet.Cells) <> 0 Then
With Sheet
lng = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
End With
Else
lng = 1
End If
LastOccupiedRowNum = lng
End Function
I used the record macro function to create this code and now I understood the problem with it.
Please help me to get a solution
Thanks in advance.