Delete rows

N

nc

Sub test()

Selection.Rows.EntireRow.Delete

End Sub

Can you help ammend the above code to stop the row (selection) being deleted
if the cell in column A has a number.
 
M

Mike H

Hi,

Try this but note empty cells are treated as numeric. Post back and tell us
what should happen to empty cells

If Not (IsNumeric(Cells(ActiveCell.Row, 1))) Then
ActiveCell.EntireRow.Delete
End If

Mike
 
D

Dave Peterson

Option Explicit
sub test2()
dim myRng as range
dim myCell as range
dim DelRng as range

'just in case there's more than one area selected
set myrng = selection.areas(1).entirerow.columns(1) 'column A

for each mycell in myrng.cells
with mycell
if application.isnumber(.value) then
'skip it
else
if delrng is nothing then
set delrng = .cells
else
set delrng = union(delrng, .cells)
end if
end if
end with
next mycell

if delrng is nothing then
'nothing to delete
else
delrng.entirerow.delete
end if
end sub
 
D

Don Guillett

Sub DeleteIfNOTnumber()
Columns(1).SpecialCells(xlCellTypeConstants, 2) _
.EntireRow.Delete 'Select
End Sub
 
J

Jacob Skaria

Do you mean

Sub Mac()
For lngRow = Selection.Rows.Count + _
Selection.Row - 1 To Selection.Row Step -1
If Not IsNumeric(Range("A" & lngRow).Text) Then
Rows(lngRow).Delete
End If
Next
End Sub

If this post helps click Yes
 
S

Shane Devenshire

And yet another variations

With Selection
If Not IsNumeric(Cells(.Row, 1)) Then .EntireRow.Delete
End With
 
N

nc

Sorry, didn't work. Deleted any rows.

Shane Devenshire said:
And yet another variations

With Selection
If Not IsNumeric(Cells(.Row, 1)) Then .EntireRow.Delete
End With

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire
 
N

nc

sorry, please disregard my prior comment. your macro did not delete the row
with a blank cell in column A.
 
Top