PDA

View Full Version : Solved: IsNumber question



ukdane
03-19-2009, 05:53 AM
I need to use VBA to check if a cell value contains a number. and if not, it needs to delete the entire row.

How do I use the IsNumber function in VBA?

'loop through all the items
Range("A1").Select
Do While ActiveCell.Row < RowCount
If (IsNumber(ActiveCell.Value)) = True Then 'check to see if the active cell contains a number
End if 'if it is a number then loop
Else
Selection.EntireRow.Delete 'if it isn't a number, delete the entire row
Range("A" & ActiveCell.Row - 1).Select
'activate the cell above, and continue the loop
MsgBox ("NOT A NUMBER")
End If
Range("A" & ActiveCell.Row + 1).Select
Loop

Bob Phillips
03-19-2009, 05:57 AM
Use IsNumeric, a builtin VBA function.

Dr.K
03-19-2009, 07:37 AM
You can also check to see if cell has a formula and a value, or just a value. Its a property for any cell:

If Cells(1, 1).HasFormula = True Then

mdmackillop
03-19-2009, 10:34 AM
Have a look at SpecialCells as well. Some options there.