+ Reply to Thread
Results 1 to 9 of 9

Not of Double Type but within Double Type Range?

Hybrid View

  1. #1
    Registered User
    Join Date
    10-12-2012
    Location
    Philippines
    MS-Off Ver
    MSO 2013
    Posts
    15

    Not of Double Type but within Double Type Range?

    Hi Everyone,

    I am getting a Type Mismatch for this value 0.291666666666667 as Double I'm not sure anymore why because:

    Double
    Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.


    The number I highlighted in blue should be within that range but why the Type Mismatch Error?


    Thanks

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Not of Double Type but within Double Type Range?

    What's the actual code that gives the error?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,330

    Re: Not of Double Type but within Double Type Range?

    Hi,

    Are you using this Double in a function that expects a TEXT string? Are you using this Double when the function is expecting a RANGE of cells instead of a number?

    We really need to see the formula or a sample of the workbook to understand what you are seeing.

    To attach a workbook, click on "Go Advanced" and then the Paper Clip Icon above the advanced message box.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    10-12-2012
    Location
    Philippines
    MS-Off Ver
    MSO 2013
    Posts
    15

    Re: Not of Double Type but within Double Type Range?

    im actually trying to look for values that are of time type only the column would only have either a string or time and since time is in decimal form in vba i did this

    and also note that for any value less than 7:00 AM or 0.291666666666667, it does work... for example 5:00 AM, 5:30 AM...

    for i = 1 to max_row
       possibletimevalue = range("A" & i).value
       if vartype(possibletimevalue) = 5 then
           converteddecimaltotime = convertdecimaltotime(cdbl(possibletimevalue))
       end if 
    next
    
    function convertdecimaltotime(atimeindecimal as double) as date
    'code to convert decimal to time type
    end function

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Not of Double Type but within Double Type Range?

    Works OK here. Can you post a workbook where it fails?

  6. #6
    Registered User
    Join Date
    10-12-2012
    Location
    Philippines
    MS-Off Ver
    MSO 2013
    Posts
    15

    Re: Not of Double Type but within Double Type Range?

    Hi Gurus,

    Thanks for taking the time and apologies for the misleading topic because I found what caused the error:

    Here's my actual code for converting decimal to time
    Function DecimalToTime(TimeInInt As Double) As Date
        Dim DTT As Double 'i forgot to declare my DTT variable, somehow not declaring this caused the Type Mismatch error
        DTT = TimeInInt * 24
        DecimalToTime = TimeValue(Int(DTT) & ":" & ((DTT - Int(DTT)) * 60))
    End Function
    I'll mark this now as resolved! Thanks again...
    Last edited by exceltabz; 05-08-2014 at 10:59 AM. Reason: changed DTT(integer) DTT(Double) type

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Not of Double Type but within Double Type Range?

    Or
    Function DecimalToTime(TimeInInt As Double) As Date
        DecimalToTime = CDate(TimeInInt)
    End Function
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    10-12-2012
    Location
    Philippines
    MS-Off Ver
    MSO 2013
    Posts
    15

    Re: Not of Double Type but within Double Type Range?

    Wow thanks, this makes thing a lot simplier!

    Quote Originally Posted by shg View Post
    Or
    Function DecimalToTime(TimeInInt As Double) As Date
        DecimalToTime = CDate(TimeInInt)
    End Function

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Not of Double Type but within Double Type Range?

    You're welcome.

+ 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. Replies: 0
    Last Post: 09-03-2013, 11:26 AM
  2. Maths using Double type
    By SteveCurrie in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-27-2011, 09:03 AM
  3. convert textbox value from string to either single or double numeric data type
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2011, 06:40 PM
  4. Comparing type double variables of different lengths
    By paulmezick in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2007, 12:55 PM
  5. Type mismatch using rnge as Range with Type 8 Input Box
    By STEVE BELL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-03-2005, 01:10 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