PDA

View Full Version : excel vba error 13 mismatch



idnoidno
06-23-2017, 06:40 AM
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?

mana
06-23-2017, 06:50 AM
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

SamT
06-23-2017, 07:01 AM
Try

dic.Add arr(i, 1), 0
Or

CStr(Clng(dic(arr(i, 1))) + 1)
But not both at once

idnoidno
06-23-2017, 07:01 AM
dic Add.arr(i,1),""
dic(arr(i,1))=dic(arr(i,1))+1

Can both not use in the sametime?

SamT
06-23-2017, 07:04 AM
Can both not use in the sametime?dic Add.arr(i,1),"" --- string
dic(arr(i,1))=dic(arr(i,1))+1 --- number

idnoidno
06-23-2017, 07:50 AM
dic Add.arr(i,1),""
dic Add.arr(i,1), 0
They are string and number,why do they get the same result?

SamT
06-23-2017, 10:07 AM
Only sometimes, but, you do as you want.