+ Reply to Thread
Results 1 to 6 of 6

Trying to find in this code whats causing error 13 Type mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Trying to find in this code whats causing error 13 Type mismatch

    Good morning,
    I got this code and tested using sample sheet and worked

    But then i change the range And start to display error 13 Type mismatch.

    I read the following link but i can't identify the correlation of possible causes vs my code


    https://msdn.microsoft.com/en-us/vba...XM04lwSTgmg)()

    I need to see what's causing this error

    This is the range what i changed
    v = Range("T5:W" & Columns("T:W").Find("*", [T1], , , 1, 2).Row)
    Then i changed to S5:W and SW

    And this
    Range("Y5").Offset(0, c - 1).Resize(.Count).Value = Application.Transpose(.Keys)
    Changed to

    Range("X5").Offset(0, c - 1).Resize(.Count).Value = Application.TRANSPOSE(.Keys)
    Then above line is Highlited

       Sub FilterDay()
    
       Dim v, s, r&, c&, i&, j&, k&
        
        v = Range("S5:W" & Columns("S:W").Find("*", [S1], , , 1, 2).Row)
        
        With CreateObject("Scripting.Dictionary")
            .CompareMode = 1
            For c = 1 To UBound(v, 2)
                For r = 1 To UBound(v, 1)
                    If InStr(v(r, c), ",") Then
                        s = Split(v(r, c), ",")
                        For j = 0 To UBound(s) - 1
                            For k = j + 1 To UBound(s)
                                If s(j) > s(k) Then: Temp = s(k): s(k) = s(j): s(j) = Temp
                            Next k, j
                        .Item(Join(s, ",")) = ","
                    End If
                Next r
                
                Range("X5").Offset(0, c - 1).Resize(.Count).Value = Application.TRANSPOSE(.Keys)
                .RemoveAll
                
            Next c
        End With
      
    End Sub

    Thanks in advance !!!!
    Last edited by AndyJr; 05-16-2018 at 06:31 AM. Reason: following rules, html brackets

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

    Re: Trying to find in this code whats causing error 13 Type mismatch

    Try changing the code to this and take a look at dic when you get the error.
       Sub FilterDay()
    
       Dim v, s, r&, c&, i&, j&, k&
       Dim dic As Object
        v = Range("S5:W" & Columns("S:W").Find("*", [S1], , , 1, 2).Row)
        
        Set dic = CreateObject("Scripting.Dictionary")
        
        With dic
            .CompareMode = 1
            For c = 1 To UBound(v, 2)
                For r = 1 To UBound(v, 1)
                    If InStr(v(r, c), ",") Then
                        s = Split(v(r, c), ",")
                        For j = 0 To UBound(s) - 1
                            For k = j + 1 To UBound(s)
                                If s(j) > s(k) Then: Temp = s(k): s(k) = s(j): s(j) = Temp
                            Next k, j
                        .Item(Join(s, ",")) = ","
                    End If
                Next r
                
                Range("X5").Offset(0, c - 1).Resize(.Count).Value = Application.Transpose(.Keys)
                .RemoveAll
                
            Next c
        End With
      
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Trying to find in this code whats causing error 13 Type mismatch

    Before writing values to the sheet, make sure that the dictionary is populated.
    Try it like this...

    If .Count > 0 Then
        Range("X5").Offset(0, c - 1).Resize(.Count).Value = Application.Transpose(.Keys)
    End If
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,591

    Re: Trying to find in this code whats causing error 13 Type mismatch

    Just change one line
                Range("X5").Offset(0, c - 1).Resize(.Count).Value = Application.Transpose(.Keys)
    to
                If .Count Then Range("X5").Offset(0, c - 1).Resize(.Count).Value = Application.Transpose(.Keys)

  5. #5
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: Trying to find in this code whats causing error 13 Type mismatch

    Thank you all!!!

    I'll test it right now


  6. #6
    Registered User
    Join Date
    10-14-2017
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    83

    Re: Trying to find in this code whats causing error 13 Type mismatch

    Hi,



    Added the:
    If .Count Then
    and worked!!!

    Thank you so much!!!!!!

+ 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 causing me issues
    By lediable007 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-11-2016, 10:23 PM
  2. Help with VBA Type 13 Mismatch error code
    By nealasmothers in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-04-2015, 04:07 PM
  3. [SOLVED] Using Range.clearcontents causing type mismatch error in code
    By Captian LDS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-28-2014, 04:54 PM
  4. Type Mismatch in my code, whats wrong?
    By Simon.Ward in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-21-2013, 11:42 AM
  5. type mismatch error in code
    By strikeofdawn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2008, 08:34 PM
  6. Type Mismatch error in VBA code
    By bobby in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2005, 04:10 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