+ Reply to Thread
Results 1 to 6 of 6

Type mismatch error

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Type mismatch error

    Hello

    I want to use this worksheet function in the AfterUpdate event of textbox4 of userform frmCustomers
    Please Login or Register  to view this content.
    but this produced run-time error 13 "Type mismatch".

    Stucked
    Attached Files Attached Files
    Last edited by ImranBhatti; 02-02-2017 at 01:10 PM. Reason: To upload workbook
    Teach me Excel VBA

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Type mismatch error

    I am not sure what is giving you this specific error but your COUNTIF call is incorrect. The syntax is

    COUNTIF(range, criteria)

    This is your call:

    CountIf(Sheets("SoldOut").Range("B7:B1048576"), Sheets("SoldOut").Range("B7:B1048576") & "")

    I don't understand what you are trying to do with that call. The second parameter is a range concatenated with a null string so will return the value in B7 as a string. I doubt that is what you intended.

    The following examples of correct syntax:


    CountIf(Sheets("SoldOut").Range("B7:B1048576"), Sheets("SoldOut").Range("C3"))


    CountIf(Sheets("SoldOut").Range("B7:B1048576"), 5)



    CountIf(Sheets("SoldOut").Range("B7:B1048576"), ">10")
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Type mismatch error

    Quote Originally Posted by 6StringJazzer View Post
    I am not sure what is giving you this specific error but your COUNTIF call is incorrect. The syntax is

    COUNTIF(range, criteria)

    This is your call:

    CountIf(Sheets("SoldOut").Range("B7:B1048576"), Sheets("SoldOut").Range("B7:B1048576") & "")

    I don't understand what you are trying to do with that call. The second parameter is a range concatenated with a null string so will return the value in B7 as a string. I doubt that is what you intended.
    I want to use the sheet level function in VBA.Here is the link of sheet level function.
    http://www.excelforum.com/showthread...t=#post4574196

    I hope this will help to know what I am asking help for.

    Best Regards
    Imran Bhatti

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Type mismatch error

    Now I see. The COUNTIF is within a SUMPRODUCT, and the COUNTIF contains arrays. I don't think VBA function evaluation will handle this the same way that the Excel worksheet functions handle it. The Evaluate function will more directly evaluate a formula exactly as Excel would evaluate it in a worksheet.

    Try this:

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Type mismatch error

    Quote Originally Posted by 6StringJazzer View Post

    Try this:

    Please Login or Register  to view this content.
    First of all thanks a lot for reviewing my long awaiting thread.
    I would say it solved the problem 50%. Remaining is that it is summing for only Invoices which are consecutive for a a customer.i.e. in my newly attached workbook there are many invoices for Mis with some other invoices of other customers in between and the Evaluate code is summing only the top invoices for Mis.

    Your help will be much appreciated.

    Best Regards
    Imran Bhatti

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Type mismatch error

    I correctly converted the sheet formula into VBA but your latest post indicates that the sheet formula is wrong to begin with. Since I didn't create it, I will have to see if I can figure out what it's doing.

+ 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] type mismatch error
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-08-2014, 04:21 PM
  2. [SOLVED] Type mismatch error
    By sthiru in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2013, 02:46 PM
  3. Run Type error 13 Type Mismatch
    By Affan Khan in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-13-2012, 12:58 PM
  4. [SOLVED] Run-type error 13 type mismatch
    By misop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-05-2012, 04:08 AM
  5. Complile Error: Type Mismatch ??? After adding error trap
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2012, 03:50 PM
  6. Conditional Formatting - Run Time Error '13' Type Mismatch Error
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2011, 07:37 PM
  7. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

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