christianbiker
Active Member
- Joined
- Feb 3, 2006
- Messages
- 365
Is it possbile using a loop or some other code to make a search using the dictionary function restricted to certain data within a spreadsheet? In the code below I have used the dictionary function and it works quite well with some of my spreadsheets however I want to use it with a large spreadsheet and pull data based on a certain criteria. In the range I have selected it is telling me the occurrence and how many times it has occurred which is great. I want to do the same thing however isolate certain the information returned based on a cruteria I specify. For instance, say I have 4 different types of data in column "A" (A, B, C, D) and I want to see all of the occurrences in the range selected but only from one of the 4 different data types that I specify, such a "B". This may not be a great explanation but hopefully someone can help me.
Thanks
Dim dic As Object, r As Range, rng As Range
Set dic = CreateObject("scripting.dictionary")
dic.comparemode = vbTextCompare
Set rng = Sheets("UNIT DATA").Range("I2:AZ10000")
For Each r In rng
If Not IsEmpty(r) Then
If Not dic.exists(r.Value) Then
dic.Add r.Value, 1
Else
dic(r.Value) = dic(r.Value) + 1
End If
End If
Next
On Error GoTo nodata
Sheets("OCCURRENCE TOTALS").Range("a2").Resize(dic.Count) = _
Application.Transpose(dic.keys)
Sheets("OCCURRENCE TOTALS").Range("b2").Resize(dic.Count) = _
Application.Transpose(dic.items)
Set dic = Nothing
Thanks
Dim dic As Object, r As Range, rng As Range
Set dic = CreateObject("scripting.dictionary")
dic.comparemode = vbTextCompare
Set rng = Sheets("UNIT DATA").Range("I2:AZ10000")
For Each r In rng
If Not IsEmpty(r) Then
If Not dic.exists(r.Value) Then
dic.Add r.Value, 1
Else
dic(r.Value) = dic(r.Value) + 1
End If
End If
Next
On Error GoTo nodata
Sheets("OCCURRENCE TOTALS").Range("a2").Resize(dic.Count) = _
Application.Transpose(dic.keys)
Sheets("OCCURRENCE TOTALS").Range("b2").Resize(dic.Count) = _
Application.Transpose(dic.items)
Set dic = Nothing