+ Reply to Thread
Results 1 to 4 of 4

How to compare time values in different cells - type mismatch

  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    How to compare time values in different cells - type mismatch

    Hi,

    I'm sure this is really simple but I just can't get the syntax right and google has not come to my aid.

    I have some code which compares the value in a cell to a timeserial value to determine if the time is before or after 4pm them asigns the result to a boolean variable (true or fasle).

    I want to alter the code to compare to another cell value rather than a hardcoded time serial (ultimately for a bit of future proofing to allow the users to change the '4pm' value if need be.

    The first line of the If statement below is what I have at the moment which doesn't work and the Esleif line is as it was before which works - just so you can see what I mean:

    Please Login or Register  to view this content.
    I've tried .value, encasing in TimeValue, etc, but can't get it quite right. The value in the first cell is 0.4652777...778 and in the named range 0.666666...667 (checked in the imediate window) so not sure why it can't compare them...

    Any help appreciated, as always. TC

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: How to compare time values in different cells - type mismatch

    attach please a sample file
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,620

    Re: How to compare time values in different cells - type mismatch

    What's in Range("TimeIDCol")?
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: How to compare time values in different cells - type mismatch

    Apologies for not coming back straight away - I finish work a bit earlier on a Friday.

    Anyway, I looked at this with fresh eyes today and it works perfectly - looks like I was just being a bit of a numbnuts!

    Here's the code that works in case anyone is interested:

    Please Login or Register  to view this content.
    Norie - the TimeIDCol is a named range containing the column number of the TimeID column (I have a series of ranges that are populated with column and row numbers on the workbook open event).

    Thanks for responding anyway. TC

+ 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. Run-time error '13': Type mismatch
    By Sky188 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2013, 03:07 PM
  2. [SOLVED] Clearing cells within an Array - Run-time error 13 (Type mismatch)
    By Wobbigone in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2013, 01:37 AM
  3. [SOLVED] Time [type mismatch]
    By Neisany in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-10-2012, 01:53 PM
  4. [SOLVED] "Run-time error '13': Type mismatch" when deleteing multiple cells from targeted columns
    By mweickdival in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2012, 01:09 PM
  5. run-time 13 Type mismatch
    By simonsmith in forum Excel General
    Replies: 2
    Last Post: 05-18-2006, 11:14 AM

Tags for this Thread

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