dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] IsNumeric in Excel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    294

    Resolved [RESOLVED] IsNumeric in Excel

    Hi!

    I'm trying to write a simple macro in Excel that will skim through my worksheets and tell me if something in the current column is not numeric. I've read a few sites that say you shouldn't use IsNumeric...but I want to. And I'm gonna.

    So with that said, here's my problem. Before the following code even starts to execute, I get an error saying "Wrong number of arguements or invalid property assignment". Can anyone tell me what's going on here?

    Code:
    Sub IsNumeric()
        Dim c, k, l As Long
        Dim s As String
        
        l = Cells.SpecialCells(xlCellTypeLastCell).Row
        c = ActiveCell.Column
        
        For k = 1 To l
            s = Cells(k, c).Text
            
            If IsNumeric(s) = False Then
                Cells(k, c).Activate
                MsgBox "Non-Numeric characters found!"
                Exit Sub
            End If
        Next k
        
        MsgBox "Complete!" & vbNewLine & vbNewLine & "No alpha characters found!"
        
    End Sub

  2. #2
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: IsNumeric in Excel

    Try naming your subroutine "MyIsNumeric" ... just a quick guess.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    294

    Re: IsNumeric in Excel

    OH WOW!!!! I'M A MORON!!!!! Let's write a sub with the same name as a function...it's brilliant!!!!

    Thanks dude.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,409

    Re: [RESOLVED] IsNumeric in Excel

    Note that IsNumeric("12d-2") returns true, and the same goes for "10e5", but not "7q3".

    It's fine to use it as long as you don't care about things like that, but there are usually safer/better ways to check whatever it is you want.


    On a separate note, you haven't declared your variables quite right, see this article for info: What's wrong with Dim x, y, z As Long ?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    294

    Re: [RESOLVED] IsNumeric in Excel

    Ya I know - it should be c as long, x as long, blah blah. But it still works so meh. lol

    Thanks though.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width