Delete rows based on criteria.

leelabird

New Member
Joined
Jun 21, 2017
Messages
5
Hi everyone,
I hope that someone can help me with a little problem.
I have an Excel file into which data is dumped daily to sheet1. In each cell in column H, there are text values and numeric values. There is never a combination of both (alpha numeric). I wish to delete all rows associated with the text values only automatically. We currently do this manually and it is very time consuming as there are a varying number of rows but rarely more than 5000. The columns range from A to AK.
Thank you for any assistance.
Regards,
Leela.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the Board!

Try this code:
Code:
Sub MyDeleteRows()

    Dim lrow As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column H
    lrow = Cells(Rows.Count, "H").End(xlUp).Row
    
'   Loop through all rows backwards
    For r = lrow To 1 Step -1
'       Delete text rows
        If Not IsNumeric(Cells(r, "H")) Then Rows(r).Delete
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Hi Leela,

Welcome to MrExcel.

Try this code-

Code:
Sub remove_text()
'assumes headers in row 1.
Dim lr As Long
Dim x As Long


lr = Worksheets("Sheet1").Cells(Rows.Count, "H").End(xlUp).Row

With Sheets("Sheet1") 'change name to suit.
For x = lr To 2 Step -1
    y = Cells(x, 8).Value
    If WorksheetFunction.IsNumber(y) = False Then
    .Rows(x).EntireRow.Delete
    
    End If
    Next x
End With
End Sub

I have assumed Col H is the longest column.

I have also assumed that your sheet1 is literally "Sheet1".

cheers,

FarmerScott
 
Upvote 0
Hi Leela,

Here' another method:-

Code:
Sub DeleteRws()

Range("H2", Range("H" & Rows.Count).End(xlUp)).SpecialCells(2, 2).EntireRow.Delete

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Hi there Joe, Farmer Scott & Vcoolio.
Thank you all for the replies. I'm now spoilt for choice! All the codes supplied work wonderfully.
@ Vcoolio:
Wow! So short, sweet and to the point! It works exceptionally well and in an instant.
I'll more than likely use your code but will certainly store all of them away for future reference.
Many thanks again to you all for being so kind to a complete stranger.

Regards,
Leela
 
Upvote 0
You're welcome Leela.
Glad that we were able to help.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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