+ Reply to Thread
Results 1 to 10 of 10

Run-time Error 13 Type Mismatch with CountIf

  1. #1
    Registered User
    Join Date
    07-27-2017
    Location
    Canada
    MS-Off Ver
    MS Office 2010
    Posts
    9

    Run-time Error 13 Type Mismatch with CountIf

    Hello guys,

    I'm rookie for VBA/macros, and I have encountered this Run Time Error 13 when I try to use the Format Painter, copy down (Ctrl+D), drag and copy etc.

    Here is my code, can someone please help me with this issue? Really appreciated! Thanks!

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Application.CountIf(Range("E:E"), Target) > "1" Then
    MsgBox "This duplicate document has already been entered! Please enter next duplicate document.", vbCritical, "Change Entry"
    Target.Value = ""
    End If
    End Sub
    Attached Files Attached Files
    Last edited by ceshi25; 07-27-2017 at 02:09 PM. Reason: Workbook attached

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Run-time Error 13 Type Mismatch with CountIf

    Hi ceshi25, welcome! "1" is text. Countif returns a number. You can't compare the two. Try this:
    Please Login or Register  to view this content.
    Please click the Add Reputation star below any helpful posts, and if you have your answer, mark your thread as SOLVED (Thread Tools up top). Thanks!-Lee
    Last edited by leelnich; 07-27-2017 at 01:12 PM.

  3. #3
    Registered User
    Join Date
    07-27-2017
    Location
    Canada
    MS-Off Ver
    MS Office 2010
    Posts
    9

    Re: Run-time Error 13 Type Mismatch with CountIf

    I tried removing the quotes around the 1, but still getting the same error when I try to copy down.. When I click on 'Debug', this line is highlighted : If Application.CountIf(Range("E:E"), Target) > 1 Then

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Run-time Error 13 Type Mismatch with CountIf

    Countif can usually handle different data types. We'd have to see your workbook to tell what's going on. Just show us typical Column E:E values and Target cells, so we can see what you're comparing.

    To attach a workbook:
    Click Edit Post (or just start a new reply.)
    Click Go Advanced
    Scroll down to Manage Attachments and click.
    Now just Browse for your file, then click Upload. Simple!

  5. #5
    Registered User
    Join Date
    07-27-2017
    Location
    Canada
    MS-Off Ver
    MS Office 2010
    Posts
    9

    Re: Run-time Error 13 Type Mismatch with CountIf

    hey leelnich, I have attached the workbook. thanks in advance!

  6. #6
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Run-time Error 13 Type Mismatch with CountIf

    I'm not getting an error. What steps should I follow to reproduce it?

  7. #7
    Registered User
    Join Date
    07-27-2017
    Location
    Canada
    MS-Off Ver
    MS Office 2010
    Posts
    9

    Re: Run-time Error 13 Type Mismatch with CountIf

    When I select and drag to populate the date and B, the run-time error 13 pops up.Capture1.PNG

  8. #8
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Run-time Error 13 Type Mismatch with CountIf

    AHHHAAAHH! COUNTIF wants a single cell. The error is raised when you change multiple cells all at once. Try this:
    Please Login or Register  to view this content.
    Please click the Add Reputation star below any helpful posts, and if you have your answer, mark your thread as SOLVED (Thread Tools up top). Thanks!-Lee
    Last edited by leelnich; 07-27-2017 at 03:29 PM.

  9. #9
    Registered User
    Join Date
    07-27-2017
    Location
    Canada
    MS-Off Ver
    MS Office 2010
    Posts
    9

    Re: Run-time Error 13 Type Mismatch with CountIf

    Omg thanks so much, such a lifesaver!!! Though could you explain why CountIf only wants a single cell?

  10. #10
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Run-time Error 13 Type Mismatch with CountIf

    That's just how the function works. It CAN be used with arrays, but then it returns an array. To check for multiple matches, loop through Target.Cells.

+ 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 celias in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-04-2016, 09:50 PM
  2. [SOLVED] COUNTIF function giving Type Mismatch error
    By Utzja1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2016, 07:34 AM
  3. Run-time error 13 (Type Mismatch)
    By prajesh in forum Excel General
    Replies: 11
    Last Post: 11-15-2011, 05:43 AM
  4. Run Time Error '13'. Type Mismatch
    By TonyforVBA in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-08-2010, 09:29 AM
  5. Run time error '13' : Type Mismatch
    By opg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2008, 02:31 PM
  6. Run-time error '13':Type mismatch
    By Sibilia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2005, 03:54 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