sarfarazbutt
Board Regular
- Joined
- Jun 10, 2009
- Messages
- 55
Below macro is deleting empty row, I would like to have combine macro which can delete also the rows if text found in first cell "Not found" and top of this row also delete. i.e if row 40 found "Not found" text delete this row and 39 row should be delete. any idea
Option Explicit
Sub DeleteEmptyRows()
Dim LastRow As Long
Dim Cnt As Long
Dim r As Long
Application.ScreenUpdating = False
LastRow = Cells.Find(what:="*", _
after:=Range("A1"), _
LookIn:=xlFormulas, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlPrevious, _
MatchCase:=False).Row
For r = LastRow To 1 Step -1
If WorksheetFunction.CountA(Rows(r)) = 0 Then
Rows(r).Delete
Cnt = Cnt + 1
End If
Next r
Application.ScreenUpdating = True
MsgBox Cnt & " rows were deleted.", vbInformation
End Sub
Option Explicit
Sub DeleteEmptyRows()
Dim LastRow As Long
Dim Cnt As Long
Dim r As Long
Application.ScreenUpdating = False
LastRow = Cells.Find(what:="*", _
after:=Range("A1"), _
LookIn:=xlFormulas, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlPrevious, _
MatchCase:=False).Row
For r = LastRow To 1 Step -1
If WorksheetFunction.CountA(Rows(r)) = 0 Then
Rows(r).Delete
Cnt = Cnt + 1
End If
Next r
Application.ScreenUpdating = True
MsgBox Cnt & " rows were deleted.", vbInformation
End Sub