+ Reply to Thread
Results 1 to 3 of 3

'If ActiveCell.Value = "#NUM!" Then' error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    'If ActiveCell.Value = "#NUM!" Then' error

    Hi all

    I've got an If function that checks whether the active cell value is less than 9 and if so, sends an email.
    Problem is, a good 50 entries will be "#NUM!" when I come to run this macro again which will mean I have to write out around 150 emails.

    Is there some way of writing an If that will pick up on the #NUM! error?

    Currently have the following:
    If ActiveCell.Value < 9 Then 
    ValidDays = ActiveCell.Value 
    Else
    Exit Sub
    End Sub
    Tried the following:

    If ActiveCell.Value < 9 Then
    ValidDays = ActiveCell.Value 
    Else
         If ActiveCell.Value = "#NUM!" Then
         ValidDays = "0" 
         End If
    End If
    Thanks

    #####################################

    Fix:
    If IsError(ActiveCell) Then
    ValidDays = "0"
    Else
        If ActiveCell.Value < 9 Then
            ValidDays = ActiveCell.Value
            Else
            Exit Sub
        End If
    End If
    Last edited by Aaron092; 08-12-2014 at 10:14 AM. Reason: Found a fix through Google

  2. #2
    Registered User
    Join Date
    08-08-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: 'If ActiveCell.Value = "#NUM!" Then' error

    You need to use .text instead of .value as the data types for errors will never match.

    Try this:

    Sub test()
    Dim validdays As Long
    If ActiveCell.Text < 9 Then
    validdays = ActiveCell.value
    Else
         If ActiveCell.Text = "#NUM!" Then
         validdays = 0
         End If
    End If
    MsgBox validdays
    End Sub
    Martinez
    Last edited by martinez77; 08-12-2014 at 11:31 AM.

  3. #3
    Registered User
    Join Date
    08-11-2014
    Location
    London, England
    MS-Off Ver
    Excel 14
    Posts
    12

    Re: 'If ActiveCell.Value = "#NUM!" Then' error

    perhaps this ....
        With ActiveCell
            Select Case True
                Case IsError(.value)
                Case Not IsNumeric(.value)
                Case .value >= 9
                Case .value < 0
                Case Else
                    validdays = .value
            End Select
        End With
    .text can have its own problems.
    Last edited by neilbro; 08-12-2014 at 11:44 AM. Reason: one more case

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] If Range("K" & ActiveCell.Row) = "" Then (ERROR)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2013, 04:56 PM
  2. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  3. For each loop, 1004 error, if ... then "activecell.offset" attempt
    By AdamParker in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-22-2010, 03:30 PM
  4. How to set the Activecell of "Sheet2" to Activecell of "Sheet1"
    By shawnh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-06-2010, 11:12 PM
  5. Replies: 0
    Last Post: 04-03-2007, 10:26 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1