Macro to Remove Specific Rows

linaeum66

New Member
Joined
Jul 2, 2017
Messages
25
I'm interested in a macro that removes an entire row if the sentence in cell "O' doesn't end in a period. Also if the macro could ignore the first row which is headings.
Thanks for your help, greatly appreciated.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Code:
Option Explicit


Sub NoPeriod()
    Dim i As Long, lr As Long
    lr = Cells(Rows.Count, "O").End(xlUp).Row
    For i = lr To 2 Step -1
        If InStr(1, Range("O" & i), ".") = 0 Then
            Range("O" & i).EntireRow.Delete
        End If
    Next i


End Sub
 
Upvote 0
Thank you for the quick response. This macro worked perfectly on a small file (100 rows) but when I tried to use it on a large file of 7000 rows it gave me the following error "type mismatch". Is there any way to work around that?
Thanks again for your help, greatly appreciated.

Code:
Option Explicit


Sub NoPeriod()
    Dim i As Long, lr As Long
    lr = Cells(Rows.Count, "O").End(xlUp).Row
    For i = lr To 2 Step -1
        If InStr(1, Range("O" & i), ".") = 0 Then
            Range("O" & i).EntireRow.Delete
        End If
    Next i


End Sub
 
Upvote 0
Scratch that, It is working now! thanks


Thank you for the quick response. This macro worked perfectly on a small file (100 rows) but when I tried to use it on a large file of 7000 rows it gave me the following error "type mismatch". Is there any way to work around that?
Thanks again for your help, greatly appreciated.
 
Upvote 0
Code:
Option Explicit


Sub NoPeriod()
    Dim i As Long, lr As Long
    lr = Cells(Rows.Count, "O").End(xlUp).Row
    For i = lr To 2 Step -1
        [B][COLOR="#FF0000"]If InStr(1, Range("O" & i), ".") = 0 Then[/COLOR][/B]
            Range("O" & i).EntireRow.Delete
        End If
    Next i


End Sub
One possible problem with the red colored code line above... if the sentence has an abbreviation in it, but doesn't have a period at the end, for example...

Dr. Smith went home

this code line will not let that row be deleted. Change the red highlighted line of code to this and it should then work in all circumstances..

If Cells(i, "O").Value Like "*[!.]" Then
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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