Consulting

Results 1 to 7 of 7

Thread: excel vba error 13 mismatch

  1. #1

    excel vba error 13 mismatch

    Sub ts()Dim arr, brr
    Dim i As Long, m As Long
    Dim dic As Object
    
    
    Set dic = CreateObject("scripting.dictionary")
    arr = Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row)
    For i = 1 To UBound(arr)
        If Not dic.exists(arr(i, 1)) Then
            dic.Add arr(i, 1), ""
        Else
            dic.Item(arr(i, 1)) = dic.Item(arr(i, 1)) + 1
        End If
    Next i
    [c1].Resize(dic.Count) = Application.Transpose(dic.keys)
    [d1].Resize(dic.Count) = Application.Transpose(dic.items)
    Set dic = Nothing
    End Sub

    I was in the implementation of CODE, this one CODE, dic.Item(arr(i, 1)) = dic.Item(arr(i, 1)) + 1
    can not be implemented, I would like to ask for help?

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
        Set dic = CreateObject("scripting.dictionary")
        arr = Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row)
        For i = 1 To UBound(arr)
            dic(arr(i, 1)) = dic(arr(i, 1)) + 1
        Next i
        [c1].Resize(dic.Count) = Application.Transpose(dic.keys)
        [d1].Resize(dic.Count) = Application.Transpose(dic.items)
        Set dic = Nothing

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Try
     
    dic.Add arr(i, 1), 0
    Or
    CStr(Clng(dic(arr(i, 1))) + 1)
    But not both at once
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    dic Add.arr(i,1),""
    dic(arr(i,1))=dic(arr(i,1))+1

    Can both not use in the sametime?

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Can both not use in the sametime?
    dic Add.arr(i,1),"" --- string
    dic(arr(i,1))=dic(arr(i,1))+1 --- number
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    dic Add.arr(i,1),""
    dic Add.arr(i,1), 0
    They are string and number,why do they get the same result?

    Last edited by idnoidno; 06-23-2017 at 08:08 AM.

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Only sometimes, but, you do as you want.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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