Remove all rows that contain letters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to create a macro or something to remove an entire row, if any
cell in the row contains any letter.I plan to use a button to automate the
process.
Thank you
 
This sub will do it, if by "contains any letter" you mean "contains any
non-numeric cell." You need to supply the range - any continuous range that
spans the rows you want to check. It uses the COUNT function and the COUNTA
function as a way of finding non-numeric cells (since these will differ if
there are any).

Public Sub RemoveAlphaRows(RowsToCheck As Range)

Dim RowNo As Integer, CheckRow As Range
Dim NumCount As Integer, AllCount As Integer

For RowNo = RowsToCheck.Rows.Count To 1 Step -1
Set CheckRow = RowsToCheck.Range("A1").Offset(RowNo - 1, 0).EntireRow
NumCount = WorksheetFunction.Count(CheckRow)
AllCount = WorksheetFunction.CountA(CheckRow)
If AllCount <> NumCount Then CheckRow.Delete
Next RowNo

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top