问题描述
我已经将Dictionary设置为对象,为该字典添加了几个项目,但是它似乎是区分大小写的。有没有我可以设置字典来识别不同的版本?
I have set Dictionary as an object an added several items to that dictionary, however it seems to be case-sensitive. Is there anyway I can set the dictionary to recognize different versions?
我的代码:
Sub Test()
Dim sheet1 As String
Dim Dict As Object
Dim c As Range
Sheet1= "TEST"
Set Dict = CreateObject("Scripting.Dictionary")
Dict.Add "MIKE", 0
Dict.Add "PHIL", 0
Dict.Add "Joe", 0
For Each c In ActiveWorkbook.Worksheets(Sheet1).UsedRange
If Dict.Exists(ActiveWorkbook.Worksheets(Sheet1).Cells(c.Row, c.Column).Value) Then
Dict(ActiveWorkbook.Worksheets(Sheet1).Cells(c.Row, c.Column).Value) = Dict(ActiveWorkbook.Worksheets(Sheet1).Cells(c.Row, c.Column).Value) + 1
End If
Next
Sheet1.Cells(25, 3) = Dict("MIKE")
Sheet1.Cells(25, 3) = Dict("PHIL")
Sheet1.Cells(25, 3) = Dict("Joe")
Set Dict = Nothing
End Sub
所以我想识别MIKE的mike和PHIL等的Phil。
So I want to recognize "mike" for MIKE and "Phil" for PHIL etc.
Th
推荐答案
我总是喜欢为我所有的编码设置直线。所以,在编写任何其他代码之前,所有模块和代码都放在我的工作表或表单中,从以下三行开始。
I always like to set things straight for all of my coding. So, all modules and code lying on my sheets or in forms start with the following three lines before writing any additional code.
Option Base 0
Option Explicit
Option Compare Text
如果我想要有东西因为某些原因在特定的 Sub
中处理不同,那么我只在这个特定的子
中执行,并按照建议上面的评论(示例):
If I want to have something handled differently in a particular Sub
for some reason, then I do so in this particular sub
only and do as proposed in the comment above (example):
dict.CompareMode = BinaryCompare 'if I need a case-sensitive compare in this sub
这篇关于案例敏感词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!