Loop Depending On Search Result.

dager6

New Member
Joined
Aug 1, 2014
Messages
11
Hi,

I am trying to improve my code for find and remove the empty row below the cells that contain "12-2014".

Unfortunately, I could not figure this out. Your help will be deeply appreciated.


PHP:
Cells.Find(What:="12-2014", After:=ActiveCell, LookIn:=xlFormulas, _        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _        MatchCase:=False, SearchFormat:=False).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate            If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp            Cells.FindNext(After:=ActiveCell).Activate        If ActiveCell.Offset(1, 1) = "" Then ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp

Best,

Matt
 
if you want to delete the entire row go from bottom row to top row with a loop
can you try to write the macro now.
 
Upvote 0
Not all the empty rows. Just the ones below "12-2014". The search function is from top down. My code does the search 12 times and delete all the rows below the ones that has "12-2014". I want to have a better code to only delete the empty rows no matter how many times "12-2014" appears.

Thanks for your reply.

Best,

Matt
 
Upvote 0
Please find my updated Code below. The problem is that it deletes rows contain "12-2014" for 16 times no matter the deleted rows are empty or not.

Code:
Dim n As Long
    n = 1
    
    Application.ScreenUpdating = False
    
    Range("A1").Select
    
    Cells.Find(What:="12-2014", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    
    For n = 1 To 16
    
        If ActiveCell.Offset(1, 1) = vbNullSting Then
            n = n + 1
            ActiveCell.Offset(1, 1).EntireRow.Delete Shift:=xlUp
            Cells.FindNext(After:=ActiveCell).Activate
        Else
            n = 16
        End If
    
    Next
            
    Application.ScreenUpdating = True
How can I fix this?

Thanks,

Matt
 
Upvote 0
The cell below was not empty. It has a space, which makes it looks empty.

Thanks for all the help.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top