delete row if cell in column contains text

dialup

Board Regular
Joined
Jan 10, 2008
Messages
99
Hi clever people, i know this has to be easy but i just can't get it.
I have a sheet full of data, column c should be all numbers but sometimes contains text instead, i need a macro to check column c and if the cell contains text instead of a numer to delete the whole row, the number of rows changes.

thanks in advance
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
This little macro will do it. Just adjust the Sheet2 name to your own sheetname.
Code:
Option Explicit
Sub TextDeleteC()
Dim cell As Range, rng As Range
Dim lastrow As Long

lastrow = Sheets("Sheet2").UsedRange.Rows.Count

Set rng = Sheets("Sheet2").Range("C2:C" & lastrow)

    For Each cell In rng
        If Not Application.WorksheetFunction.IsNumber(cell.Value) Then
        cell.EntireRow.Delete
        End If
    Next cell
End Sub

Alt-F11 to open the VBEditor
Click on Insert > module
Paste in the code above
Alt-F11 to close the editor
Save your sheet.

Run the macro.
 
Last edited:
Upvote 0
Just a wee shorter...basically the same macro:
Code:
Option Explicit
Sub TextDeleteC()
Dim cell As Range, rng As Range
Dim lastrow As Long

lastrow = Sheets("Sheet2").UsedRange.Rows.Count

Set rng = Sheets("Sheet2").Range("C2:C" & lastrow)

    For Each cell In rng
        If Not Application.WorksheetFunction.IsNumber(cell.Value) Then cell.EntireRow.Delete
    Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

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