Results 1 to 4 of 4

Thread: Type mismatch

  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Praha
    Posts
    988
    Thanks
    56
    Thanked 105 Times in 90 Posts

    Type mismatch

    Excel 2003

    I am working on error handling in a complicated procedure: the error condition I am getting is Type mismatch. I know what causes it - it is an occasional fault in imported data that is not in my control.

    As the Workbook is only used by me, I would have been content simply to debug the error on the rare occasions it arises, except that it crashes Excel completely !

    I know how to use the VBA error handler, but I'd rather test for the error and either fix it or bring it to my attention in a more orderly manner than an Excel crash.

    My question is how do I test for the data type of a cell read (or to be read) into a VBA module ?

    Thanks

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    Does the function at http://www.j-walk.com/ss/excel/tips/tip62.htm do what you need?Steve

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    If you are getting an error reading the value of a cell, you can simply use
    Code:
    If Not IsError(cell.value) then
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Praha
    Posts
    988
    Thanks
    56
    Thanked 105 Times in 90 Posts
    Thanks, Steve and Rory.

    I was subtracting two cells, one imported, when I got the error.

    A test to see if the CellType of each is the same trapped the problem, although I have settled on the more specific IsNumeric test on both cells before executing the subtraction.

    Martin

Posting Permissions

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