简而言之,我们从一个应用程序(而不是我们自己的应用程序)中得到一个excel中的报告,它将每个提交的单个表单中的所有用户响应放入一个单元格中。我正试图为Office:mac编写一个VBA宏。
因此,“修饰符”列中的单个单元可能如下所示:
单元1:第一任教师选择:Gunderson;第二位教师选择:Barnes;您喜欢果冻吗?是的;超人还是绿巨人?
单元2:第一任教师选择:史密斯;第二位教师选择:Gunderson;您喜欢果冻吗?是的
细胞3:第一任教师选择:伍芬巴赫;第二任教师选择:丰塔纳;你喜欢果冻吗?不;超人还是绿巨人?超人?超人?
单元4:第一任老师选择丰塔纳;第二位教师选择:史密斯;你喜欢果冻吗?是的;超人还是绿巨人?
单元5:第一任教师选择外差;第二位教师选择:伍尔芬巴克;你喜欢果冻吗?是的;超人还是绿巨人?超人?
我的目标是收集所有的问题(在;和\\之间的文本),为每个问题创建一个列,然后用答案填充这些列。我设想哈希表如下:
{
"1st Teacher Choice":{1:"Gunderson", 2:"Smith", 3:"Wulfenbach", 4:"Fontana", 5:"Hetrodyne"},
"2nd Teacher Choice":{1:"Barnes", 2:"Gunderson", 3:"Fontana", 4:"Smith", 5:"Wulfenbach"},
"Do you like Jello?":{1:"yes", 2:"yes", 3:"no", 4:"yes", 5:"yes"},
"Superman or Hulk":{1:"Hulk", 2:"",3:"Superman",4:"Superman",5:"Superman"}
}现在,在做完所有的序言之后,下面是我要开始工作的代码:
Dim modifierColumn As Integer
Dim rawModifiers As String
Dim oneMod As String
Dim oneResp As String
Dim modifierList As Dictionary
Set modifierList = New Dictionary
For theRow = 2 To lastRow
'Get the string of modifiers in the current row
rawModifiers = Cells(theRow, modifierColumn).value
'Break each modifier string in the row into a separate array element
rowModifiersArray = Split(rawModifiers, ";")
'Iterate through each of the modifiers and value in the new array
For Each modResp In rowModifiersArray
'Seperate the modifier from the response in another temp array, 'singleModifier’.
'The first element of the array will be the name of the modifier, the second will be the response to the modifier.
singleModifier = Split(modResp, "|")
oneMod = singleModifier(0)
oneResp = singleModifier(1)
'If the modifier exists as a key in the ModifierList, add the row and the value into the dictionary associated to that key
'If the modifier has already been entered in modifierList, add the row and value to the sub-dictionary
If (Not modifierList.Exists(oneMod)) Then
modifierList.Add oneMod, New Dictionary
End If
'ERROR IS THROWN ON LINE BELOW
modifierList(oneMod).Add theRow, oneResp
Next
Next theRow上面的代码只是创建了哈希表。在此之后创建列非常简单,因此为了本问题的目的,我将忽略它。
我已经安装了由Patrick‘’Bierne在他出色的博客创建的外接程序字典和KeyValue类。但是,我从底部得到一个运行时错误('438'),在第三行中声明"Object不支持此属性或方法“,并标记为注释。第一个字典.Add方法工作得很好。有什么想法吗?这可能是类实现中的错误吗?
发布于 2014-09-06 23:25:55
看来你需要更明确一点
而不是
modifierList(oneMod).Add theRow, oneResp尝尝这个
modifierList.KeyValuePairs(oneMod).value.Add theRow, oneResphttps://stackoverflow.com/questions/25691779
复制相似问题