Consulting

Results 1 to 4 of 4

Thread: Solved: IsNumber question

  1. #1
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location

    Solved: IsNumber question

    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?

    [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[/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Use IsNumeric, a builtin VBA function.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Jun 2007
    Posts
    150
    Location
    You can also check to see if cell has a formula and a value, or just a value. Its a property for any cell:

    [vba]If Cells(1, 1).HasFormula = True Then[/vba]

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Have a look at SpecialCells as well. Some options there.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •