Consulting

Results 1 to 9 of 9

Thread: IsNumber not working

  1. #1

    IsNumber not working

    [VBA]

    For Each x In Range("B:B")
    If x.Row > LastCell Then: Exit For
    If IsEmpty(x.Value) Then: x.Value = "30"
    If IsNumber(x.Value) Then
    Select Case (x.Value)
    Case 0 To 20: TotalPastDue = TotalPastDue + Range("L" & x.Row) _
    - Range("C" & x.Row) - Range("D" & x.Row)
    Case 20 To 30: TotalPastDue = TotalPastDue + Range("L" & x.Row) _
    - Range("C" & x.Row) - Range("D" & x.Row) - Range("E" & x.Row)
    Case 30 To 45: TotalPastDue = TotalPastDue + Range("L" & x.Row) _
    - Range("C" & x.Row) - Range("D" & x.Row) - Range("E" & x.Row) - Range("F" & x.Row) _
    - Range("G" & x.Row)
    Case 45 To 120: TotalPastDue = TotalPastDue + Range("L" & x.Row)
    End Select
    Next x
    [/VBA]

    For some reason IsNumber brings up an error message saying "Sub or Function not defined.". What am i doing wrong?

  2. #2
    If statement was causing an error, please delete this thread.
    Thanks.

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you use Option Explicit and compile your code before use, any such errors will be revealed.
    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'

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    IsNumber throws a runtime error with or without Option Explicit, so there was enough info there.
    ____________________________________________
    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

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    He won't as far as any IsNumber runtime error with the If ... Next code as written.
    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'

  6. #6
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    ISNUMBER is a spreadsheet function.
    IsNumeric is a VB function.

  7. #7
    i thought that "Option Explicit" just forces you to declare all your vars, how will it reveal errors like this one?
    IsNumeric is a VB function.
    VB is so much more complicated than the first language that i learned, i'm going to be making those rookie mistakes for a looooooong time.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by next
    i thought that "Option Explicit" just forces you to declare all your vars, how will it reveal errors like this one?
    Why not give it a try?
    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'

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop
    He won't as far as any IsNumber runtime error with the If ... Next code as written.
    I did.
    ____________________________________________
    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

Posting Permissions

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